Ng-Model-Options-1

 

Ng-Model is used as bridge between model and view and it also provide validation behavior. All the other directive are dependent on <code>ng-model</code> as this will remember the state of controls. It also provide setting related css classes on the element (ng-valid, ng-invalid, ng-dirty, ng-pristine, ng-touched, ng-untouched, ng-empty, ng-not-empty) including animations. See the code:

 
 
 
<!DOCTYPE html> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <title></title> <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.4.2/angular.min.js"></script> <link rel="stylesheet" href="http://maxcdn.bootstrapcdn.com/bootstrap/3.2.0/css/bootstrap.min.css"> </head> <body ng-app="myApp"> <div ng-controller="myController"> <div class="container"> <label> Name: <input type="text" class="form-control" name="userName" ng-model="user.name" ng-model-options="{ updateOn: 'blur' }" /> </label><br /> <label> Other data: <input type="text" class="form-control" ng-model="user.data" /> </label><br /> <pre>user.name = <span ng-bind="user.name"></span></pre> </div> </div> <script> var app = angular.module("myApp", []); app.controller('myController', ['$scope', function ($scope) { }]); </script> </body> </html>
Output