Decision:
"If you are using an ng model, you must have a point."
Make your model point in object.property and you will go well.
controller
$scope.formData = {}; $scope.check = function () { console.log($scope.formData.searchText.$modelValue);
Template
<input ng-model="formData.searchText"/> <button ng-click="check()">Check!</button>
This happens when child areas are in the game - for example, children's routes or ng-repeats. The child array creates its own value, and a name conflict occurs as shown here :
See this video for more information: https://www.youtube.com/watch?v=SBwoFkRjZvE&t=3m15s .
And this applies to the links below:
Other solutions
Use the this instead of $scope , Details
And also you can get more details from this below two discussions
Ng model does not update controller value
Why is my ng-model variable undefined in the controller?
Solution for update 1:
Please declare an empty object first at the top of your controller:
var app = angular.module('myApp', []); app.controller('myCtrl', function($scope) { $scope.name = ""; $scope.a = function(){alert($scope.name);} });
I hope this helps you.
source share