If I want to a service or constant available as a dependency on the directive, it fails. Looking at the demo, this works:
myApp.directive('magenta', function () {
return {
restrict: 'E',
replace: true,
templateUrl: 'directives/magenta/directive-magenta.html',
css: {
href: 'directives/magenta/directive-magenta.css',
/* Preload: this will trigger an HTTP request on app load.
* Once the stylesheet is added, it will be loaded from the browser cache */
preload: true
}
}
});
But this does not
myApp.directive('magenta', function ($log) {
$log.debug("in magenta directive");
return {
restrict: 'E',
replace: true,
templateUrl: 'directives/magenta/directive-magenta.html',
css: {
href: 'directives/magenta/directive-magenta.css',
/* Preload: this will trigger an HTTP request on app load.
* Once the stylesheet is added, it will be loaded from the browser cache */
preload: true
}
}
});
If I'm understanding the way this works, the directive factory is executed once in angular-cs.js to find the css definition and add appropriate event handlers.
var directive = angular.copy(originalDirectiveFactory)();
And when this fails, it is silently ignored (since many directives dont have css and might be written such that they might fail).:
However, this ignores the dependencies required by the factory. It looks like as long as the factory, itself, doesn't access the dependencies, or guards for undefined, and can return an object that has at least the the css def, it should work. In my case, I had a $log.debug that failed, because the $log is undefined, but was also using a constant to defined part of the path to the css and template.
Do you think it would it be feasible to use the $injector, so that the factory can execute properly as it would in normal use?
If I want to a service or constant available as a dependency on the directive, it fails. Looking at the demo, this works:
But this does not
If I'm understanding the way this works, the directive factory is executed once in angular-cs.js to find the css definition and add appropriate event handlers.
var directive = angular.copy(originalDirectiveFactory)();
And when this fails, it is silently ignored (since many directives dont have css and might be written such that they might fail).:
However, this ignores the dependencies required by the factory. It looks like as long as the factory, itself, doesn't access the dependencies, or guards for undefined, and can return an object that has at least the the css def, it should work. In my case, I had a $log.debug that failed, because the $log is undefined, but was also using a constant to defined part of the path to the css and template.
Do you think it would it be feasible to use the $injector, so that the factory can execute properly as it would in normal use?