双方向バインディングの分離スコープを持つディレクティブ myDirective があります。ユーザーがボタンをクリックしたときに、Isolate スコープを値に変更したいと考えています。分離スコープは $scope にバインドされていると思っていましたが、間違っています。その分離スコープを「つかんで」操作するにはどうすればよいですか? ディレクティブ コントローラーのスコープにアタッチされていませんか?
angular.module("app", [])
.controller("myCtrl", function($scope){
$scope.ctrlTwoway = "Eggs";
})
.directive("myDirective", function(){
return {
scope: {
twoway: =
},
template: "<button ng-click="changeTwoway()">Change two way isolate scope</button>",
controller: function($scope, $element, $attrs){
$scope.changeTwoway = function(){
// get twoway from isolate scope, and update the value with "bacon"
// $scope.twoway = "bacon" doesn't work
// nor does $attrs.twoway = "bacon" work, either :(
};
}
}
});
そしてHTML
...
<div my-directive twoway="{{ctrlTwoway}}"></div>
Current value: {{ctrlTwoway}}