加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > 安全 > 正文

angularjs – Angular typeahead,设置自定义弹出模板

发布时间:2020-12-17 17:38:54 所属栏目:安全 来源:网络整理
导读:无论如何都要为typeahead-popup设置自定义模板? “typeahead-template-url”指令仅适用于弹出窗口中的每个匹配项. 这是我的代码: input class="select-location" id="Location" type="text" ng-model="model.location" ng-keypress="keypress($event)" typ
无论如何都要为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">

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读