gpt4 book ai didi

javascript - AngularJS - 指令范围中无法访问范围值

转载 作者:行者123 更新时间:2023-11-28 19:53:44 25 4
gpt4 key购买 nike

FIDDLE

我创建了一个指令:-

return {
restrict: 'EAC',
scope: {
statesActive: '='
},
link: function (scope, element, attrs) {
var stateData = scope.statesActive.states; // Don't get data here
....
}

我的 HTML :-

<gt-map states-active="states"></gt-map>

Controller :-

$scope.statesList = function () {
var query = {
status: 'active'
}

StatesList.query(query).$promise.then(function (states) {
$scope.states = states;
});
};

我在这样的状态下获取数据:-

$scope.states = "{states:[{ 'state' : 'CA', 'color' : '#61c419']}";

如何获取指令中的Controller范围值?

-----已添加-----

这是我在指令中的 console.log(scope) 中看到的:-

enter image description here

最佳答案

return {
restrict: 'EAC',
scope: {
statesActive: '='
},
link: function (scope, element, attrs) {
var stateData = angular.fromJson(attrs.statesActive).states; // Probably, your "states" model here
....
}

关于javascript - AngularJS - 指令范围中无法访问范围值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22978663/

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