angularjs - 动态加载纳克重复模板里面 [英] angularjs - dynamically load template inside ng-repeat

查看:127
本文介绍了angularjs - 动态加载纳克重复模板里面的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想一个NG重复中动态加载模板:

 < UL>
    <李NG重复=托在实体>
        < D​​IV NG-包括SRC =prop.template>< / DIV>
    < /李>
< / UL>

prop.template等于模板的网址,例如: '谐音/表格/ text.html。以上code产生以下错误:

 错误:$ 10摘要()迭代到达。中止!
在过去的5次迭代发射观察家:[[prop.template;的newval:\\的谐音/表格/ text.html \\; OLDVAL:未定义,prop.template;的newval:\\的谐音/表格/ text.html \\; OLDVAL:未定义......(等等)

我如何获得prop.template模板的URL,并插入从该文件HTML到内的DOM NG-重复?


解决方案

  

http://docs.angularjs.org/api/ng 。$ rootScope.Scope #$摘要


  
  

处理所有当前的范围及其子女的观察家。由于观察者的听众可以改变模型中,$摘要()保持调用观察家直到没有更多的听众被解雇。这意味着,有可能进入无限循环。此功能会抛出最大迭代超过限制。如果迭代的数量超过10


问题不是关于code在这里,应该完美的工作。看到这里工作的例子: http://jsfiddle.net/fmjf8/2/

问题是,要么你可以有你的 ngRepeat ING数组中的元素过多或模板阵列,还是要包括做太多的东西模板,提高棱角分明的无限循环的保护。我投给了第二个

I am trying to dynamically load a template within an ng-repeat:

<ul>
    <li ng-repeat="prop in entity" >
        <div ng-include src="prop.template"></div>
    </li>
</ul>

prop.template equals the url of the template e.g. 'partials/form/text.html'. The above code produces the following error:

Error: 10 $digest() iterations reached. Aborting!
Watchers fired in the last 5 iterations: [["prop.template; newVal: \"partials/form/text.html\"; oldVal: undefined","prop.template; newVal: \"partials/form/text.html\"; oldVal: undefined" .... (and so on)

How do I get the url of the template from prop.template and insert the html from that file into the DOM within ng-repeat?

解决方案

http://docs.angularjs.org/api/ng.$rootScope.Scope#$digest

Process all of the watchers of the current scope and its children. Because a watcher's listener can change the model, the $digest() keeps calling the watchers until no more listeners are firing. This means that it is possible to get into an infinite loop. This function will throw 'Maximum iteration limit exceeded.' if the number of iterations exceeds 10.

The problem is not about the code here, it should be working perfectly. See the working example here: http://jsfiddle.net/fmjf8/2/

The problem is either you may have too many elements in your ngRepeating array OR the template your array, or the template you are including is doing too many stuff, raising angular's infinite loop protection. I vote for the second

这篇关于angularjs - 动态加载纳克重复模板里面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆