I am new with angular js.
my controller is : var myapp= angular.module('myapp', ['ngRoute']);
// configure our routes
myapp.config(function($routeProvider) {
$routeProvider
// route for the home page
.when('/', {
templateUrl : 'pages/person.html',
controller : 'personController'
})
// route for the contact page
.when('/add', {
templateUrl : 'pages/addGroup.html',
controller : 'groupController'
});
});
myapp.controller('groupController', function($scope) {
$scope.user = 'alex';
$scope.print = function()
{
alert($scope.user);
};
});
my view is :
<div ng-controller="groupController">
Your name: <input type="text" ng-model="user">
<button ng-click='print()'>Print</button>
{{user}}
</div>
when I change the input value to "mila" for example its reflect in the view, but when I click the print button I am still getting alert with "alex" name.
how can I make the scope.user to change also ? I cant understand what is missing here for 2 way data binding. thanks !