【发布时间】:2016-03-28 16:54:37
【问题描述】:
我正在尝试制作一些可重复使用的倒计时小部件。适用于静态内容,但是当我尝试动态添加它们时,我的指令不理解 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';
...
}
...
感谢您的回复。
【问题讨论】:
-
不是答案,而是观察:范围应该是 $scope
-
嗯,在文档中它的链接功能范围
-
这就是你所说的!约定是内置函数和变量以 $ 开头。
-
实际上,将其称为范围而不是 $scope 更有意义。当你使用 $scope 时,当你使用依赖注入时 - 当 Angular 将根据变量名查找依赖时。