无论如何都要为typeahead-popup设置自定义模板?
“typeahead-template-url”指令仅适用于弹出窗口中的每个匹配项.
这是我的代码:
<input class="select-location" id="Location" type="text" ng-model="model.location" ng-keypress="keypress($event)" typeahead="match for match in getLocations($viewValue)" typeahead-template-url="matchUrl"/>
解决方法
您可以使用AngularJS装饰器,它允许您在实例化时修改指令(也包括服务和任何内容).
它们是AngularJS的猴子补丁版本.将来如果要修改其他指令,则在使用.decorator方法时,模式如下.
[nameOfDirective]指令例如: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
关于装饰的Official Documentation.
A service decorator intercepts the creation of a service,allowing it to override or modify the behavIoUr of the service. The object returned by the decorator may be the original service,or a new service object which replaces or wraps and delegates to the original service.
更新
从角度引导程序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">