Using $provide.decorator
$provide using $provide to decorate this directive, avoid the need for direct traversal with $templateCache .
Instead, create your external html template, as usual, with whatever name you want, and then override the templateUrl directive to point to it.
angular.module('plunker', ['ui.bootstrap']) .config(['$provide', Decorate]); function Decorate($provide) { $provide.decorator('alertDirective', function($delegate) { var directive = $delegate[0]; directive.templateUrl = "alertOverride.tpl.html"; return $delegate; }); }
Fork pkozlowski.opensource plunkr: http://plnkr.co/edit/RE9AvUwEmKmAzem9mfpI?p=preview
(Note that you must add the suffix "Directive" to the name of the directive you are about to decorate. We decorate the UI Bootstrap alert directive above, so we use the name alertDirective .)
As you often can do more than just override templateUrl , this provides a good starting point for further expanding the directive, for example, by redefining / wrapping a link or compilation function ( for example ).
JcT Oct 13 '14 at 12:22 2014-10-13 12:22
source share