I'm starting using Angular JS to build a mobile application with Ionic.
I'm trying a thing very simple but it does not work.
HTML
<div ng-controller="MyCtrl">
Hello, {{name}}!
</div>
<div ng-controller="MyCtrl2">
Hello, {{name}}!
</div>
<button ng-controller="MyCtrl" ng-click="MyCtrl.test()">click</button>
JS
var myApp = angular.module('myApp', []);
function MyCtrl($scope) {
$scope.name = 'Name 1';
$scope.test = function () {
$scope.name = 'Name on click !';
}
}
function MyCtrl2($scope) {
$scope.name = 'Name 2';
}
I have a similar structure in my Ionic App. I need to modify the "$scope.name" from another template. Thanks for help.
JSFiddle : http://jsfiddle.net/ADukg/6649/