Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angularjs/21.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Angularjs 来自变量的自定义模板_Angularjs_Angular Ui Bootstrap - Fatal编程技术网

Angularjs 来自变量的自定义模板

Angularjs 来自变量的自定义模板,angularjs,angular-ui-bootstrap,Angularjs,Angular Ui Bootstrap,我使用的是Angular Bootstrap的typehead,它提供了一个属性:typeahead template url,可用于设置自定义HTML模板以显示typehead项。在本例中,在html中将其设置为:customTemplate.html,并按如下方式创建模板: <script type="text/ng-template" id="customTemplate.html"> <a> <img ng-src="http://uploa

我使用的是Angular Bootstrap的typehead,它提供了一个属性:typeahead template url,可用于设置自定义HTML模板以显示typehead项。在本例中,在html中将其设置为:customTemplate.html,并按如下方式创建模板:

<script type="text/ng-template" id="customTemplate.html">
  <a>
      <img ng-src="http://upload.wikimedia.org/wikipedia/commons/thumb/{{match.model.flag}}" width="16">
      <span bind-html-unsafe="match.label | typeaheadHighlight:query"></span>
  </a>
</script>
我可以在我的主JavaScript文件中定义这个模板,而不是像上面那样为它创建一个脚本标记吗

我正在寻找类似于:

HTML:

JS:


$templateCache.puttpl.html,?是的,这很有效。如果你把它作为答复提交,我将接受。
<input typehead=".." typeahead-template-url="tpl.html" />
Angular.setTemplate( 'tpl.html', '<a href="{{item.url}}">{{item.name}}</a>' )