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

angularjs – 如何在单独的文件中分离ng-template

发布时间:2020-12-17 07:31:37 所属栏目:安全 来源:网络整理
导读:我正在使用 angularUI typehead作为输入元素.我正在使用自定义模板来显示值.一切正常.我的问题是如何将ng-template分成单独的文件,以便它也可以在其他文件中重复使用. 如果我的话不清楚,请注意我特指的是ng-templates而不关心其他单独的html内容 这是代码:
我正在使用 angularUI typehead作为输入元素.我正在使用自定义模板来显示值.一切正常.我的问题是如何将ng-template分成单独的文件,以便它也可以在其他文件中重复使用.

如果我的话不清楚,请注意我特指的是ng-templates而不关心其他单独的html内容

这是代码:

// custom template begin 
 // this is the ng-template
 // I'd like to move this custom template into to another file 
 // similar to partials
 <script type="text/ng-template" id="customTemplate.html">
    <a>
        <b>{{match.model.name}}</b>
        <div>{{match.model.username}}</div>
    </a>
</script>
 //custom template end


// input element makes use of the ng-template defined above
<div class="form-group">
<label class="col-md-2 control-label normal" for="assignTo">Assign To</label>
 <div class="col-md-3">
    <input name="bug_assignTo" id="bug_assignTo" ng-model="bug.assignTo" typeahead="user.username as user.name for user in config.users | filter:$viewValue | limitTo:8" class="form-control input-sm" typeahead-on-select="bug.assignTo = $item" placeholder="type name" typeahead-template-url="customTemplate.html"></input>
 </div>

将它放在一个部分不起作用,例如:
< div ng-include =“app / client / bug / new / my-ng-template.partial.html”>< / div>
抛出:

Tried to load angular more than once.
 [$rootScope:infdig] 10 $digest() iterations reached. Aborting!
...
....
您不需要ng-include.

将模板移动到单独的文件中,假设文件名为customTemplate.html
和文件内容一样

<a>
    <b>{{match.model.name}}</b>
    <div>{{match.model.username}}</div>
</a>

不要包含< script type =“text / ng-template”id =“customTemplate.html”>将标记移动到单独的文件中时标记.

使用正确的文件路径,如

<input name="bug_assignTo" 
               id="bug_assignTo" 
               ng-model="bug.assignTo" 
               typeahead="user.username as user.name for user in config.users | filter:$viewValue | limitTo:8" 
               class="form-control input-sm" 
               typeahead-on-select="bug.assignTo = $item" 
               placeholder="type name" 
               typeahead-template-url="customTemplate.html" /> <!--put correct physical path here,if it is inside partial folder then use partial/customTemplate.html-->

(编辑:李大同)

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

    推荐文章
      热点阅读