AngularJS Tutorial - ng-init








ng-init set ups state inside the scope.

Example

The following code shows how to ng-init.


<!doctype html>
<html ng-app="myApp">
<head>
  <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.0-rc.2/angular.js"></script>
</head><!--from   w ww  .  j  a  v a 2s.c o  m-->
<body>

  <div ng-init="greeting='Hi'; person='AngularJS'">
    {{greeting}} {{person}}
  </div>

  <script>
    angular.module('myApp', []);
  </script>

</body>
</html>

The code above is rendered as follows: