- Ng-init directive is used to define the initial value of the application data.
- Instead of using ng-init, we will use controllers to initial the values.
Syntax for ng-init directive in AngularJS:
Parameter Values:
Value |
Description |
expression |
Denotes an expression to evaluate. |
Sample code for ng-init directive in AngularJS:
ng-init directive in AngularJS:
Code Explanation for ng-init directive in AngularJS:
- The <script> tag is used to include AngularJS JavaScript source file from googleapis.com into HTML document.
- The ng-app specifies the root element (e.g. <body> or <html> or <div> tags) to define AngularJS application.
- In AngularJS applications ng-init is used to initialize the value for expression in the current scope.
Sample Output for ng-init directive in AngularJS:
- The value Welcome to Wikitechy.com which is given within the ng-init directive is displayed in the output.
Related Searches to angularjs ng-init directive
ng-init function
angularjs init function
ng-init scope variable
ng-init w3schools
ng-init not working
ng-init multiple values
ng-init ng-repeat
angularjs ng init call function
angularjs initialize controller with data
data-ng-init
angularjs initialize variable in controller
ng-init not working
angularjs tutorials