Angular simple validation not working


Here is some plunker I have created. I cant understand why it is not working.
Here is the JS:

  angular.module('demo', [
  ]).controller('MainCtrl', function($scope)
    $ = "Vlad";
    $scope.age = 11;

    $scope.sendTest = function() 

Here is the html:

<body ng-controller="MainCtrl">
    <form name="form" novalidate>
                <label>Number: </label>
                <input type="text" min="0" max="10" ng-model="age" required />
                <label>Name: </label>
               <input type="text" ng-model="name" required />
            <button ng-click="sendTest(test)">Submit</button>

The problem is that I am getting undefined in the console (instead of true, false).


Two things.

You need to access the form fields via the form object


And to be able to do that, you need to set the name attribute on the inputs

<input type="number" name="age" min="0" max="10" ng-model="age" required />
<input type="text" name="name" ng-model="name" required />

Well, three things. You need input type="number" for min and max to work. See docs

Answered By – ivarni

Answer Checked By – Pedro (AngularFixing Volunteer)

Leave a Reply

Your email address will not be published.