Angularjs 来自变量的自定义模板
我使用的是Angular Bootstrap的typehead,它提供了一个属性:typeahead template url,可用于设置自定义HTML模板以显示typehead项。在本例中,在html中将其设置为:customTemplate.html,并按如下方式创建模板: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
<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>' )