Right now, ngSrc is set to a priority of 99, with the comment "it needs to run after the attributes are interpolated", I assume attributes are interpolated at priority 100.
I'm trying to add a new directive: gbErrorsrc, which puts in a default image if the given image fails to load. The code looks like this:
var errorSource = function () {
return {
priority: 99, // what to put here?
link: function (scope, element, attrs) {
$(element).one("error",
function() {
$(element).attr("src", attrs.gbErrorsrc).addClass("error-image");
});
}
};
};
(It assumes full jQuery is available -- probably not a good assumption, but a problem for another day.)
The problem is, for this to work properly on Internet Explorer* the error-event handler has to be set before the source attribute is set, which means this directive must run before the ngSrc directive -- but it also has to run after interpolation (in case the value of the attribute must be evaluated).
I have three roughly equi-desirable solutions:
- Discover a new integer between 99 and 100. Win the Fields Medal and retire.
- Convince the Angular people to support non-integral priorities
- Convince the Angular people to change the priority of ngSrc to 98
Actually, looking at code suggests that the priority does not have to be integral, and 99.5 seems to work. Can anyone confirm or deny? I lead a fortunate life and so don't have IE to try this on.
* The whole IE error-handling fiasco is reason #3549 why the widespread outpouring of regret that followed Steve Jobs's untimely death will not be repeated when Bill Gates finally BSODs on us. Assuming, that is, whatever Dark Lord that Gates sold his soul to didn't also spring for immortality.