以重复的指令传递数据

时间:2013-09-27 10:08:01

标签: angularjs

我想在“link”属性中访问“num”。但我不能只做value={{num}}。这样做的正确方法是什么?

HTML

<div class="customDirective" ng-repeat="num in [1,2,3]"></div>

指令

function customDirective(loggedUserService) {
    return{
        restrict: "C",
        link: function (scope, element, attrs) {
            //I would like to access num
        },
        template: "<div>some stuff</div>"
    };
}

app = angular
    .module('myApp', [])
    .directive('customDirective', customDirective)

1 个答案:

答案 0 :(得分:2)

link: function (scope, element, attrs) {
    alert(scope.num);