I'm working through some tutorials trying to firm up my grasp of isolate scope and I'm having some issues. I get the high concept but I'm trying to justify some behavior I'm seeing that I don't understand. At a high level the way I understand it, the options attached work like this:
@ - allows you to feed in a string & - provides one way data binding = - provides two way data binding
So considering the following code:
<div ng-app="choreApp">
<div ng-controller="ChoreCtrl">
<kid done="logChore(chore)"></kid>
</div>
</div>
var app = angular.module('choreApp', []);
app.controller("ChoreCtrl", function($scope){
$scope.logChore = function(chore){
alert(chore + " is done!");
};
});
app.directive("kid", function() {
return {
restrict: "E",
scope: {
done: "&"
},
template: '<input type="text" ng-model="chore">' +
'{{chore}}' +
'<div class="button" ng-click="done({chore: chore})">I\'m done</div>'
};
});
The above is wired up ok, with the '&' the logChore function works, all is well.
The '@' doesn't work, as expected, since it is just reading in a string, when I click nothing happens.
However, I also expect '=' to work ok since it's just a two way binding, however what actually happens is the function executes three times without any action on my part (the click), then is seems to function as normal. Why does the function execute three times?