AngularJS Basic ng init Simple Example

  • 2021-07-07 06:06:32
  • OfStack

AngularJS ng-init Directive

AngularJS instance

Create 1 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> ng-init  Directive creates the  AngularJS  Variable, which you can use in applications. </p>

</div>

</body>
</html>

Definition and usage

The ng-init instruction executes the given expression.

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

Grammar

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

All HTML elements support this instruction.

Parameter value

描述
expression 执行的表达式。

The above is the ng-init instruction of the data collation, friends in need of reference.


Related articles: