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