javascript - dynamic img-src with placeholder image -


i have following predicament. unfortunately can't share plunkr image coming protected site , not aware of open url serves changing images. can't switch local animated image needs on external server demonstrate problem. concept pretty straight forward.

i have following url using display image. server sending image changing image @ approximately 3 frames per second.

<img ng-src="{{logindata.url}}/cgi-bin/nph-zms?mode=jpeg&amp;monitor={{monitorid}}&maxfps=3&buffer=1000&user={{logindata.username}}&pass{{logindata.password}}&rand={{rand}}" width="100%" style="backgroundimage:url('http://placeholder.com/placeholder.jpg');"/> 

now here problem: -- want show place holder text or image following instances: a) sometimes, takes time server render first frame b) server not seem send images

what want avoid screen not remaining blank - confuses user

the problem facing moment img-src start, screen turns white , in few seconds images start streaming (situation above) or screen remains blank long time (situation b)

i've tried various methods: a) see in code above, i've tried background image. shows if error returned img-src (for example, forcibly change url invalid 1 or not reachable). happening me shows momentarily, moment img-src encountered screen turns white (till images start coming server)

b) i've tried various methods including app.directive global image trap method in if ngsrc path resolves 404, there way fallback default?

but core problem situation not involve error in image. seems if server gets stuck or delayed not returning error in http ==> , in duration, window image turns white. , i'd solve putting in text on top of (or image on top of it), till real images start being received.

thank

for own need, made directive displaying placeholder image if servers has error :

.directive('placeholderimg', function() {     //default place holder     return {         restrict: 'a',         link: function(scope, element, attr) {             var img = window.scriptroot + 'img/divers/avatar_min.jpg';             if (attr.placeholderimg) {                 switch (attr.placeholderimg) {                     case 'profile':                         img = 'img/avatar.png';                         break;                     case 'profile_small':                         img = 'img/avatar_min.png';                         break;                     case 'profile_large':                         img = '/img/nothumb.png';                         break;                     //add more placeholders                 }              }              //if ngsrc empty             if (!attr.ngsrc)                 element[0].src = img;              //if there error (404)             element.on('error', function() {                 element[0].src = img;             });          }     }; }); 

and use this:

<img data-ng-src="{{app.picture}}" data-placeholder-img="profile_large"> 

i understand main issue want display while image loading. maybe can modify directive, set element[0].src placeholder @ beginning of code , overloading binding load event once it's loaded (the same way have bound error event).


Comments

Popular posts from this blog

php - failed to open stream: HTTP request failed! HTTP/1.0 400 Bad Request -

java - How to filter a backspace keyboard input -

java - Show Soft Keyboard when EditText Appears -