I am a beginner and trying hard to learn Angular. I am stuck at a point where I need ng-model value in my controller. I can see that a lot of people had already asked this question but most of them never got a correct answer.
This is my code
<body ng-app="newApp">
<div ng-controller="myController2">
<input type="text" name="name" required ng-model="nameMy" id="new">
<button ng-click="showValues">Submit</button>
<p> {{nameMy}} </p>
</div>
</body>
Angular
var newApp = angular.module('newApp', []);
newApp.controller('myController2', function($scope){
$scope.showValues = function(){
console.log($scope.nameMy);
}
$scope.showValues();
});
I $scope.nameMy is giving me undefined, I have also tried the dot rule in model name but nothing is working. I would appreciate if anybody can help.