AngularJS ng-model

The ngModel directive binds an input, select, textarea to a property on the scope using NgModelController. One can also bind same property on multiple input elements. Few points to note:

  • Change initiated from one input will propagate to all other places.
  • Change can also be initiated by modifying scope variable in Javascript.
<div ng-app="myApp">
  <input type="text" ng-model="yourName" ng-init="yourName='Rahul Gupta'">
  <input type="text" ng-model="yourName">
  <p>Hello {{yourName}}!</p>
  <input type="text" ng-model="yourCity">
  <p>in city {{yourCity}}!</p>

<script src="//"></script>
<script type="text/javascript">
  var module = angular.module("myApp", []);['$rootScope', function($rootScope){
    $rootScope.yourCity = 'Bangalore';
Share this article: share on Google+ share on facebook share on linkedin tweet this submit to reddit


Click here to write/view comments