Just when I think I'm getting a grasp on AngularJS, it throws me overboard. I am trying to have a value in the parent scope be updated by passing it through to an isolated scope and then update it there.
I thought with two way data binding this would be as simple as the following:
In Parent Controller:
var self = this;
self.variable = 'Init';
In Element:
<div data-example-directive data-variable="ParentCtrl.variable"></div>
In the child Directive:
scope: {
variable: '='
}
link: function(scope) {
scope.updateVal = function(updatedVal) {
scope.variable = updatedVal;
}
}
template: '<button ng-click="updateVal('Updated Value')"></button>'
Now, if, inside that function, I call a console.log
on the scope.variable
it displays the correct value of updatedVal
. However on the page itself, the parent hasn't been updated. Is there some sort of "refresh" I need to call?
I thought the point of AngularJS was that two-way data binding was baked in and I wouldn't have to ask it to update values based on later logic? A colleague has used a broadcast
but is there not a more elegant sollution?