从Bootstrap-UI Typeahead模板访问控制器范围

rec*_*ant 14 angularjs angular-ui-bootstrap

我无法使用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>
Run Code Online (Sandbox Code Playgroud)

问题是模板中似乎没有控制器的范围:

showItem(eqp.model)

永远不会被称为.我也尝试过:

$parent.showItem(eqp.model)

无济于事.

如何调用控制器范围内的函数/值呢?

Rog*_*ink 16

我遇到了同样的问题,看看github上的typeahead代码,看看是否可以提供任何线索.看来,建议列表的创建涉及多个指令,每个指令都有自己的子范围.

换句话说,你$parent.showItem(eqp.model)是一个很好的尝试,但你没有达到足够的水平.对我有用的是:$parent.$parent.$parent.showItem(eqp.model)