考虑下面的嵌套指令。我一直在尝试在嵌套指令的隔离范围之间绑定变量,并且无法实现双向绑定。
在示例中,我希望outerPower
绑定到并在数字增加innerPower
时更改。innerPower
检查小提琴http://jsfiddle.net/hally9k/sqea6Ln7/
testApp.directive('innerDirective', function () {
return {
scope: {
innerPower: '&'
},
template: '<div><p>Inner Power = {{innerPower}}</p>' +
'<button ng-click="increment();">Power up!</button>' +
'</div>',
controller: function ($scope, $element, $attrs) {
$scope.increment = function() {
++$scope.innerPower;
}
}
};
});
testApp.directive('outerDirective', function () {
return {
scope: {
},
template: '<div><p>Outer Power = {{outerPower}}</p>' +
'<div inner-directive inner-power="outerPower"></div>' +
'</div>',
controller: function ($scope, $element, $attrs) {
$scope.outerPower = 0;
}
};
});