angularjs ng-init directive

angularjs example

Create a variable when initializing the application:

<! Doctype html>
<meta charset="utf-8">
<script src="http://apps.bdimg.com/libs/angular.js/1.4.6/angular.min.js"></script>
<div ng-app="" ng-init="mytext =" hello world! "">
<p>The ng-init directive creates an angularjs variable that you can use in your application.

Definition and usage

The ng-init instruction executes the given expression.

The ng-init directive adds some unnecessary logic to the scope. It is recommended that you can execute it with the ng-controller directive in your controller.


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

All html elements support this directive.

Parameter value

value description
expression The executed expression.

  • Previous Clipboardjs Flash-free JavaScript copy-paste library
  • Next Android implements IOS camera slide control