AngularJS ng-init Directive

Definition and Usage

ng-init Directives evaluate the given expression.

ng-init Directives can add some unnecessary logic in the scope, it is recommended to evaluate in the controller, please refer to ng-controller Directive.

Instance

Create a variable when initializing the application:

<div ng-app="" ng-init="myText='Hello World!'">
<h1>{{myText}}</h1>

Try It Yourself

Syntax

<element ng-init="expression" ></element>

All HTML elements support.

Parameters

Parameters Description
expression To evaluate the expression.