Angularjs:ngRepeat和指导 [英] Angularjs: ngRepeat and directive
本文介绍了Angularjs:ngRepeat和指导的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我试图做一些可重复使用的倒计时小工具。与静态内容效果很好,但是当我试图把它们添加在飞行,我的指令不明白ngRepeat里面的变量。
I am trying to make some reusable countdown widgets. Works well with a static content, but when i'm trying to add them on the fly, my directive doesn't understand the variables inside the ngRepeat.
加价:
<div ng-repeat="cdn in countdowns" class="countdown" countdown-end="{{cdn}}">
<p ng-hide="over">{{days}} jours {{hours}} heures {{minutes}} min {{seconds}} sec</p>
<p ng-show="over">Done</p>
</div>
指令:
...
link: function(scope, elm, attrs) {
scope.days = '1';
...
}
...
谢谢你的答复。
推荐答案
的问题是,内插不受时间链接功能运行时被调用。所以价值 {{} CDN}
不可用。有几个处理这种方式:
The problem is that the interpolation is not run by the time link function is called. So the value of {{cdn}}
is not available. There are couple of ways of handling this:
- 您可以使用
CDN
直接在链接功能,因为它是可用的范围。但是,这将使得该指令依赖于CDN
在范围presence。 - 推荐的方式来获得使用插值属性值是使用$观察。检查: http://jsfiddle.net/hFGb7/28/
- You can use
cdn
directly in the link function since it is available on the scope. But this will make the directive dependent on the presence ofcdn
in the scope. - The recommended way to get the value of attributes that use interpolation is to use $observe. Check this: http://jsfiddle.net/hFGb7/28/
这篇关于Angularjs:ngRepeat和指导的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文