1

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.

1 Answer 1

4

You are missing () after the showvalues since it is a function

 <button ng-click="showValues()">Submit</button>

Working Plunker

Sign up to request clarification or add additional context in comments.

1 Comment

I am doing $scope.test = $scope.nameMy; and accessing it by <p> {{test}} </p> I am getting nothing. any ideas?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.