Angularjs 如何访问templateUrl html内容中angular指令的属性
如何访问templateUrl html内容中angular指令的属性Angularjs 如何访问templateUrl html内容中angular指令的属性,angularjs,angularjs-directive,Angularjs,Angularjs Directive,如何访问templateUrl html内容中angular指令的属性 angular.module('myApp') .directive('questionImage', function () { return { restrict : 'E', scope : false, templateUrl : 'templates/questionImage.html', li
angular.module('myApp')
.directive('questionImage', function () {
return {
restrict : 'E',
scope : false,
templateUrl : 'templates/questionImage.html',
link : function(scope, element, attrs) {
scope.type = attrs['type'];
}
}
});
模板HTML:
<div>
<label>Image Links</label><br>
<button type="button" ng-click="newImageLink('{{type}}')">+</button>
<span ng-repeat="imageLink in questionFormData.imageUrls['{{type}}'] track by $index">
<input type="text" ng-model="questionFormData.imageUrls['{{type}}'][$index]">
<button type="button" ng-click="removeElement(questionFormData.imageUrls['{{type}}'], $index)">-</button>
</span>
</div>
图像链接
+
-
在这个HTML中,我需要访问在DOM中使用该指令时指定的“type”属性值,如下所示
<question-image type="optionAImages"></question-image>
<question-image type="optionBImages"></question-image>
如何在html模板中获取“type”属性值
更新:在指令定义中添加了“链接”功能。我能够得到类型,但它的值始终是最后一个指令用法。
i、 e我总是看到类型
属性的选项图像
值<代码>选项图像值不可用
return {
restrict : 'E',
scope : {
type : '@'
},
templateUrl : 'templates/questionImage.html'
这相当于
scope.type = attrs.type;
这相当于
scope.type = attrs.type;
这相当于
scope.type = attrs.type;
这相当于
scope.type = attrs.type;
问题来自
scope:false
语句,因为问题图像指令的第二次调用覆盖了同一参数的第一次调用所更改的参数
您需要将范围:false
更改为范围:true
这不会创建隔离作用域,但会为指令提供控制器父作用域的嵌套作用域。问题来自
作用域:false
语句,因为问题图像指令的第二次调用覆盖了同一参数的第一次调用所更改的参数
您需要将范围:false
更改为范围:true
这不会创建隔离作用域,但会为指令提供控制器父作用域的嵌套作用域。问题来自
作用域:false
语句,因为问题图像指令的第二次调用覆盖了同一参数的第一次调用所更改的参数
您需要将范围:false
更改为范围:true
这不会创建隔离作用域,但会为指令提供控制器父作用域的嵌套作用域。问题来自
作用域:false
语句,因为问题图像指令的第二次调用覆盖了同一参数的第一次调用所更改的参数
您需要将范围:false
更改为范围:true
这不会创建隔离作用域,但会为指令提供控制器父作用域的嵌套作用域。听起来您需要隔离SCOPE@underscore我无法隔离作用域,因为我需要从父控制器获得很多功能。还可以看到我的更新,就像你需要隔离一样SCOPE@underscore我无法隔离作用域,因为我需要从父控制器获得很多功能。还可以看到我的更新,就像你需要隔离一样SCOPE@underscore我无法隔离作用域,因为我需要从父控制器获得很多功能。还可以看到我的更新,就像你需要隔离一样SCOPE@underscore我无法隔离作用域,因为我需要从父控制器获得很多功能。也可以看到我的更新