来自Bootstrap-UI Typeahead模板的angularjs – 访问控制器范围
发布时间:2020-12-18 00:21:02 所属栏目:安全 来源:网络整理
导读:我无法使用ui-typeahead从自定义模板中调用控制器函数: input typeahead="val for val in autoComplete($viewValue)" typeahead-template-url="searchAutocompleteTpl.html" ng-model="query"/script type="text/ng-template" id="searchAutocompleteTpl.ht
我无法使用ui-typeahead从自定义模板中调用控制器函数:
<input typeahead="val for val in autoComplete($viewValue)" typeahead-template-url="searchAutocompleteTpl.html" ng-model="query"/> <script type="text/ng-template" id="searchAutocompleteTpl.html"> <span ng-repeat="eqp in match.model.equipment"/> <a href="" ng-click="showItem(eqp.model)"> found in: {{eqp.model}} </a> </script> 问题是控制器的范围似乎在模板中不存在: showItem(eqp.model) 从来没有叫过我也试过: $parent.showItem(eqp.model) 无济于事 那么如何调用控制器范围的函数/值呢? 解决方法
我碰到同样的问题,看了一下
typeahead code on github,看看是否可以提供任何线索.在创建建议列表中有几个指令涉及,每个都有自己的子范围.
换句话说,你的$parent.showItem(eqp.model)是一个很好的尝试,但是你没有达到足够的水平.对我有用的是:$parent.$parent.$parent.showItem(eqp.model) (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |