Изменения в моей переменной области видимости foo
обновляются в html. Когда это значение изменяется внутри области действия контроллера директивы, оно не обновляется в html.
Что мне нужно сделать, чтобы он обновился?
У меня есть простой пример:
app.js
var app = angular.module('app', []);
app.controller('ctrl', function($scope) {
$scope.foo = 99;
$scope.changeValue = function() {
$scope.foo = $scope.foo + 1;
}
});
app.directive('d1', function(){
return {
restrict: 'E',
scope: {
theFoo: '='
},
templateUrl: 'd1.html',
controller: 'd1Ctrl',
}
});
app.controller('d1Ctrl', function($scope) {
$scope.test = $scope.theFoo;
});
d1.html
<div>
<p>The value of foo is '{{theFoo}}'.</p>
<p>The value of test is '{{test}}'.</p>
</div>
внутри index.html
<d1 the-foo='foo'>
</d1>
<button ng-click='changeValue()'>change value</button>
Таким образом, {{theFoo}}
обновляется, а {{test}}
— нет. Почему?