ng-app,ng-init
ng-app:
The ng-app directive initializes AngularJS and makes the specified element a root element of the application. Visit ng-app section for more information.
ng-init:
The ng-init directive can be used to initialize variables in AngularJS application.
We're using JSON syntax to define array of countries.
<div ng-app = "" ng-init = "countries = [{locale:'vuyyuru',name:'India'}, {locale:'vijayawada',name:'India'}, {locale:'hyd',name:'India'}]">
...
</div>
The following example demonstrates ng-init directive that initializes variable of string, number, array, and object.
Practies example: ng-init.
<html >
<head>
<script src="angular.min.js"></script>
</head>
<body >
<h2>Ng-Init Sample Code:</h2>
<div ng-app ng-init="greet='Hello World!';
amount= 100;
myArr = [100, 200];
person = { firstName:'Vision', lastName :'Computes'}">
{{amount}} <br />
{{myArr[1]}} <br />
{{person.firstName}}
</div>
</body>
</html>
Note: variables in the above example cannot be used out of <div> element.
For
More Explanation
&
Online Classes
More Explanation
&
Online Classes
Contact Us:
+919885348743
+919885348743