Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/extjs/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Angularjs 在重复指令中传递数据_Angularjs - Fatal编程技术网

Angularjs 在重复指令中传递数据

Angularjs 在重复指令中传递数据,angularjs,Angularjs,我想访问“link”属性中的“num”。但是我不能只做value={{{num}。正确的方法是什么 HTML 指示 功能自定义指令(loggedUserService){ 返回{ 限制:“C”, 链接:函数(范围、元素、属性){ //我想访问num }, 模板:“一些东西” }; } app=角度 .module('myApp',[]) .directive('customDirective',customDirective) 完美!这比我想象的要容易。非常感谢class=“customDi

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

HTML

指示
功能自定义指令(loggedUserService){
返回{
限制:“C”,
链接:函数(范围、元素、属性){
//我想访问num
},
模板:“一些东西”
};
}
app=角度
.module('myApp',[])
.directive('customDirective',customDirective)

完美!这比我想象的要容易。非常感谢
class=“customDirective”
class=“customDirective”
这两种方法都能起作用:-因为它实际上是一个css类,如果它是一个元素,它就不起作用了(restrict:“E”)我想。文档上说:
可以通过将camel case名称转换为snake case来调用该指令。
:DYep!将其作为属性或元素调用时失败。我认为文件中没有提到这一点。
<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)
link: function (scope, element, attrs) {
    alert(scope.num);