AngularJS parameter Binding--angularjs

Source: Internet
Author: User

There are three ways to bind a angularjs parameter. The first interpolation expression "{{}}" indicates that the second is represented by using the Ng-bind property in the label, and the third is represented by the Ng-module property of the input box (label). The following three small cases are set for three parameter binding methods.

1. Interpolation expressions

Case Core Code:

Demo01.html:

<! DOCTYPE html>
ng-app= "MyApp">

<meta charset= "UTF-8" >
<TITLE>ANJULARJS Data Binding-interpolation expressions </title>

<body>
<div ng-controller= "Demo01controller">
<span>{{name}}</span>
<span>{{num1+num2}}</span>
<span>{{num1*num2}}</span>
<span>{{obg.address}}</span>
<span>{{address[0]}}</span>
<ul>
<li ng-repeat= "item in the address track by $index" >{{item}}</li>
</ul>
<ul>
<li ng-repeat= "item in university" >
{{Item.name}}
<ul>
<li ng-repeat= "ChildItem in Item.xueyuan" >{{childitem}}</li>
</ul>
</li>
</ul>
</div>
<script src= ". /js/angular.min.js "></script>
<script src= ". /js/app_module.js "></script>
<script src= ". /js/demo01controller.js "></script>
</body>

Case Effect:

2, Ng-bind

Case Core Code:

demo02.html:

<! DOCTYPE html>


<meta charset= "UTF-8" >
<title>ANJULARJS Data binding-ng-bind representation </title>

<body>
<div ng-controller= "Demo02controller" >
<span ng-bind= "name"></span>
<span ng-bind= "num1+num2"></span>
<span ng-bind= "num1*num2"></span>
<span ng-bind= "obg.address"></span>
<span ng-bind= "adress[0" ></span>
<ul>
<li ng-repeat= "item in the address track by $index" ng-bind= "Item" ></li>
</ul>
<ul>
<li ng-repeat= "item in university" >
{{item.name}}<!-- here with an interpolation expression, consider why? -
<ul>
<li ng-repeat= "ChildItem in Item.xueyuan" ng-bind= "ChildItem" ></li>
</ul>
</li>
</ul>
</div>
<script src= ". /js/angular.min.js "></script>
<script src= ". /js/app_module.js "></script>
<script src= ". /js/demo02controller.js "></script>
</body>

Case effect: (same as 1)

3, Ng-module

Case Core Code:

Demo03.html:

<! DOCTYPE html>


<meta charset= "UTF-8" >
<title>anjularjs Data binding-ng-module (for input box) </title>

<body>
<div ng-controller= "Demo03controller" >
<input type= "text" ng-model= "name">
<!-- Two-way binding --
<p>{{name}}</p><!-- or <p ng-bind= "name" ></p>-->
</div>
<script src= ". /js/angular.min.js "></script>
<script src= ". /js/app_module.js "></script>
<script src= ". /js/demo03controller.js "></script>
</body>

Case Effect:

Case all code download: Angularjs parameter binding. zip

AngularJS parameter Binding--angularjs

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.