AngularJS ng-init directive
AngularJS instance
Create a variable when initializing the application:
<!DOCTYPE html><html><head><meta charset="utf-8"><script src="http://apps.bdimg.com/libs/angular.js/1.4.6/angular.min.js"></script></head><body><div ng-app="" ng-init="myText='Hello World!'"><h1>{{myText}}</h1><p> The ng-init directive creates an AngularJS variable that you can use in your application. </p></div></body></html>Definition and usage
The ng-init directive executes the given expression.
The ng-init directive adds some unnecessary logic to the scope, and it is recommended that you execute it in the ng-controller directive in the controller.
grammar
<element ng-init="expression" ></element>
All HTML elements support this directive.
Parameter value
| value | describe |
|---|---|
| Expression | The expression to execute. |
The above is a compilation of the information on the ng-init instruction, and friends who need it will refer to it.