AngularJS Tutorial - ng-model links to scope








The following code shows how to link ng-model to scope.

Example


<!DOCTYPE html>
<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.13/angular.js"></script>
<script type='text/javascript'>
function HelloCtrl($scope) {<!-- w  w w. j  ava2s  .c o  m-->
    $scope.name = 'Bob';
}
</script>
</head>
<body ng-app>
    <div ng-controller="HelloCtrl">
        <p>Hello, {{name}}</p>
        <p>Your name: <input ng-model="name" /></p>
    </div>
  
</body>

</html>

The code above is rendered as follows: