question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[src] attribute the first time it calls to an undefined endpoint

See original GitHub issue

GET http://localhost:8080/undefined 404 (Not Found)

<img [src]="data.avatar_url" width="100" height="100"/>
this.data = {};
http.get('https://api.github.com/users/danicomas').toRx().map(res => res.json()).subscribe(response => this.data = response);

Issue Analytics

  • State:closed
  • Created 8 years ago
  • Comments:23 (15 by maintainers)

github_iconTop GitHub Comments

7reactions
maziarrezaeicommented, Nov 14, 2016

The solutions above did not work for me for this situation:

[src]='getImageUrl() | async'

before the promise is resolved, I have a momentarily null value that causes the request to be triggered anyway. The solution that worked for me and can easily cover the above scenarios too is:

[attr.src]='getImageUrl() | async'

7reactions
PatrickJScommented, Aug 21, 2015

I mentioned this subtlety in this issue https://github.com/angular/angular/issues/3007 (for me it was making /null requests) the current workaround is || '' so

<img [src]="data.avatar_url || '' " width="100" height="100">

or default the initial avatar_url value to empty string (probably a good idea anyways).

I would say if interpolation gets to have a default case of empty string then [src] should as well. Here’s my code

<div>
  <img [src]="(model?.getValue('boxshot') | async) || '' ">
</div>
Read more comments on GitHub >

github_iconTop Results From Across the Web

React/Redux reducer returned undefined during initialization
I have a console.log() at the beginning and it is not being called at all. reducers/reducer_which_sorter.js import { SORT_CAMPERS } ...
Read more >
Cannot Read Property of Undefined in JavaScript - Rollbar
TypeError: Cannot read property of undefined occurs when a property is read or a function is called on an undefined variable.
Read more >
also, Platform API Endpoint /api/v2/conversations/calls/history ...
Hello, We are trying to use OpenDataExporter to get participant data values. Similarly to the other post in the Developer forum on this ......
Read more >
Queries - Redux Toolkit
Query endpoints are defined by returning an object inside the ... indicates that the query is currently loading for the first time, ...
Read more >
Setting up Axios Interceptors for all HTTP calls in an application
A lot of the time, those HTTP calls aren't so simple either: I ... the first argument passed to the response interceptor is...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Hashnode Post

No results found