Home>

angularjs ng-init directive

angularjs example

Create a variable when initializing the application:

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

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.

grammar

<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