你可以使用AngularJS修饰器,在指令(也包括服务和几乎所有东西)实例化时修改它们。
它们是AngularJS版本的猴子补丁。将来,如果您想修改其他指令,使用.decorator方法时模式如下:
[nameOfDirective]Directive,例如:typeaheadPopupDirective。
var app = angular.module("monkey", ["ui.bootstrap"]);
app.config(function ($provide) {
$provide.decorator("typeaheadPopupDirective", function ($delegate) {
$delegate[0].templateUrl = "template/typeahead/typeahead-popup-ALTERNATIVE.html";
return $delegate;
});
});
这是使用原始ui-bootstrap指令的演示。在指令尝试获取新模板URL时,您应该会收到404错误。
http://plnkr.co/edit/0mPADZ7D7Eszp07R2g60?p=preview
装饰器的官方文档。
服务装饰器拦截服务的创建,允许其覆盖或修改服务的行为。装饰器返回的对象可以是原始的服务,也可以是替换或包装并委托给原始服务的新服务对象。
更新
自angular bootstrap 0.14.x起,此功能现已受到本地支持。在typeahead
指令中,您可以使用typeahead-popup-template-url
属性指定用于弹出窗口的模板。
<input type="text" ng-model="selected"
typeahead="state for state in states | filter:$viewValue
typeahead-append-to-body="true"
typeahead-popup-template-url="customPopUp.html"
class="form-control">