AngularJS ng-initDirective
AngularJS Example
Create a variable when initializing the application:
<div ng-app="" ng-init="myText='Hello World!'">
<h1>{{myText}}</h1>
<h1>{{myText}}</h1>
Try it Yourself »
Definition and Usage
ng-initThe directive executes the given expression.
ng-initThe directive adds some unnecessary logic to the scope; it is recommended that you can do it in the controller. ng-controllerThe directive executes it.
Syntax
<element ng-init="expression" ></element>
All HTML elements support this directive.
Parameter Value
| Value | Description |
|---|---|
| expression | The expression to be executed. |
Other Extensions
AngularJS Reference Manual