angularjs – Angular typeahead,设置自定义弹出模板
无论如何都要为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.
更新 从角度引导程序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"> (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |