I have an AngularJS SPA. During the app's init I get a theme from the server, which includes a couple CSS URLs.
I want to use these, and fallback to a default if they 404.
I thought I could setup a simple directive to accomplish this but I can't get it to work right.
.directive('errorHref', function() {
return {
link: function(scope, element, attrs) {
element.bind('error', function() {
attrs.$set('ng-href', attrs.errorHref);
});
}
}
});
HTML: note, the controller is working; however, _init events in headController are firing before everything else.
<html ng-app="timeclock">
<head ng-controller="headController">
<link ng-href="{{urlToAppCSS}}" error-href="content/css/app.css" rel="stylesheet">
Is this the right approach or is there a better way? Everything seems like it should be functioning properly (and works in almost identical situations in other parts of my app), but the element.bind('error'... function never actually fires.
<link>elements trigger an error when their resource cannot be loaded? I know this works with images, but I've not seen it with link before.