I was wondering if someone could explain the behavior of this angular test application.
In the html, I have controller 2 inside controller 1.
When I click on "click on me 1" w/o having clicked on "click on me 2", $scope.message of controller 2 receives the "clicked 1" value.
Then, I click on "click on me 2". Now if I click on "click on me 1" again, $scope.message of controller 2 will not receive the "clicked 1" value anymore.
I have a theory, but would like to hear from the experts.
Thanks.
var app = angular.module("myApp", []);
app.controller("controller1", function($scope, $http, $filter) {
$scope.message = "clicked none";
$scope.clicked = function() {
$scope.message = 'clicked 1';
};
});
angular.module("myApp").controller('controller2', function($scope) {
vm = this;
vm.clicked = clicked;
function clicked() {
$scope.message = 'clicked 2';
}
});
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script>
<div ng-app="myApp">
<div ng-controller="controller1">
<div>
i'm in c1 {{ message}}
<button type="button" ng-click='clicked()'>Click Me c1!</button>
<div ng-controller="controller2 as c2">
i'm in c2 {{ message }}
<button type="button" ng-click='c2.clicked()'>Click Me c2!</button>
</div>
</div>
</div>