Lowering the priority of ngSrc

493 views
Skip to first unread message

mich...@gablit.com

unread,
May 31, 2012, 4:15:41 PM5/31/12
to ang...@googlegroups.com
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:
  1. Discover a new integer between 99 and 100.  Win the Fields Medal and retire.
  2. Convince the Angular people to support non-integral priorities
  3. 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.

Vojta Jína

unread,
Jun 13, 2012, 7:07:05 PM6/13/12
to ang...@googlegroups.com
Why do you need to execute after interpolation ?
Even if the directive is executed after interpolation, it's still gonna be before the interpolated value gets set (that's async).

Priority doesn't have to be integer, so 99.5 will work.

Btw, you don't have to wrap the element with $, it's already jq wrapper.

V.

--
You received this message because you are subscribed to the Google Groups "AngularJS" group.
To view this discussion on the web visit https://groups.google.com/d/msg/angular/-/jOaofhsKNDwJ.
To post to this group, send email to ang...@googlegroups.com.
To unsubscribe from this group, send email to angular+u...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/angular?hl=en.

Reply all
Reply to author
Forward
0 new messages