我想知道如何从 linkFn 回调中手动获取属性。
例如如果我想要范围,我愿意,
angular.element(element).scope()
Controller
angular.element(element).controller('ngModel')
attr 怎么样。
最佳答案
在父 Controller 中,我想您可以在首先将属性对象分配给指令中的范围属性后访问它:
<div ng-controller="MyCtrl">
<div my-directive attr1="one">see console log</div>
</div>
app.directive('myDirective', function() {
return {
link: function(scope, element, attrs) {
scope.attrs = attrs
},
}
});
function MyCtrl($scope, $timeout) {
$timeout(function() {
console.log($scope.attrs);
}, 1000);
}
关于angularjs - 如何以 Angular 手动获取$attr,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16697113/