AngularJS ng-initDirective

AngularJS 参考手册AngularJS Reference Manual


AngularJS Example

Create a variable when initializing the application:

<div ng-app="" ng-init="myText='Hello World!'">

<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.

AngularJS 参考手册AngularJS Reference Manual

Other Extensions