AngularJS(および関連する)ドキュメントと、ディレクティブ内の分離されたスコープに関するその他のスタックオーバーフローの質問を確認した後、私はまだ少し混乱しています。親スコープとディレクティブ分離スコープの間で双方向バインディングを実行できないのはなぜですか。親スコープのプロパティはオブジェクトであり、属性ではありません。目的のプロパティをオフに使用する必要がありますscope.$parent
か?それは間違っているようです。よろしくお願いします。
関連するフィドルはこちらです。
HTML:
<div ng-app="myApp">
<div ng-controller="myCtrl">
<div my-directive>{{test.name}}</div>
</div>
</div>
JavaScript:
var myApp = angular.module('myApp', []);
myApp.controller('myCtrl', function ($scope) {
$scope.test = {name:"name", value:"value"};
});
myApp.directive("myDirective", function () {
return {
replace: true,
restrict: 'A',
scope: {test: '='},
template: '<div class="parent"><div>This is the parent Div.</div><div>Value={{test}}</div></div>',
link: function (scope, element, attrs) {
console.log("scope.test=["+scope.test +"]");
console.log("scope.$parent.test=["+scope.$parent.test.name+"]");
}
};
});