私はangularjsの初心者です。ディレクティブの分離スコープについて少し混乱しています。私は次のコードを持っています、
HTML
<!doctype html>
<html ng-app="myApp">
<body ng-controller="componentsController">
<div class="scope-one" data-param="a">
<div class="scope-two" data-param="c"></div>
</div>
<!---->
</body>
</html>
脚本
angular.module('components', [])
.controller('componentsController', function($scope){
$scope.a = {
"b": 1
};
$scope.c = {
"d": 2
};
});
angular.module('myApp', ['components'])
.directive('scopeOne', function() {
return {
restrict: 'C',
scope: {
a: "=param"
},
link: function(scope, element, attrs) {
console.log('one', scope);
}
};
})
.directive('scopeTwo', function() {
return {
restrict: 'C',
scope: {
c: "=param"
},
link: function(scope, element, attrs) {
console.log('two', scope);
}
};
})
デモ http://jsfiddle.net/jPtb3/23/
問題
2 つのディレクティブがscope-one
あり、内部でscope-two
使用しています。の場合、分離されたスコープは適切で適切ですが、値の場合はです。問題が発生しません。何か間違っていますか? 1 つのディレクティブが別のディレクティブに含まれていない場合、分離されたスコープの値はどちらも問題ありません。scope-two
scope-one
scope-one
scope-two
undefined