View source Improve this doc

ngInit
directive in module ng

Description

The ngInit directive allows you to evaluate an expression in the current scope.

The only appropriate use of ngInit is for aliasing special properties of ngRepeat, as seen in the demo below. Besides this case, you should use controllers rather than ngInit to initialize values on a scope.
Note: If you have assignment in ngInit along with $filter, make sure you have parenthesis for correct precedence:
  <div ng-init="test1 = (data | orderBy:'name')"></div>

Usage

as attribute
<ANY ng-init="{expression}">
   ...
</ANY>
as class
<ANY class="ng-init: {expression};">
   ...
</ANY>

Directive info

  • This directive executes at priority level 450.

Parameters

ParamTypeDetails
ngInitexpression

Expression to eval.

Example

Source







Demo