Improve this Doc View Source ngInit
Improve this Doc View Source ngInit
- directive in module ng
Overview
The ngInit
directive allows you to evaluate an expression in the current scope.
This directive can be abused to add unnecessary amounts of logic into your templates. There are only a few appropriate uses of ngInit
: aliasing special properties of ngRepeat, as seen in the demo below. initializing data during development, or for examples, as seen throughout these docs. injecting data via server side scripting. Besides these few cases, you should use Components or Controllers rather than ngInit
to initialize values on a scope.
Note: If you have assignment in ngInit
along with a filter
, make sure you have parentheses to ensure correct operator precedence:
<div ng-init="test1 = ($index | toString)"></div>
Directive Info
- This directive executes at priority level 450.
Usage
as attribute:
<ANY ng-init="expression"> ... </ANY>
as CSS class:
<ANY class="ng-init: expression;"> ... </ANY>
Example
© 2010–2020 Google, Inc.
Licensed under the Creative Commons Attribution License 3.0.
https://code.angularjs.org/1.8.2/docs/api/ng/directive/ngInit