gpt4 book ai didi

angularjs - 如何以 Angular 手动获取$attr

转载 作者:行者123 更新时间:2023-12-04 02:56:04 25 4
gpt4 key购买 nike

我想知道如何从 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);
}

fiddle

关于angularjs - 如何以 Angular 手动获取$attr,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16697113/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com