This repository has been archived by the owner on Jun 8, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 45
/
expression.html
47 lines (41 loc) · 1.77 KB
/
expression.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
<!DOCTYPE html>
<html ng-app="">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />
<title>Expression - AngularJS Test</title>
<style type="text/css">
.test-div {margin:15px;padding:15px;border:1px solid #ccc;}
</style>
</head>
<body>
<div class="test-div" ng-init="bgColor='lightblue'">
<input type="text" style="background-color:{{bgColor}}" ng-model="bgColor" value="{{bgColor}}" />
</div>
<div class="test-div" ng-init="num1=2;num2=5">
<p>积:{{num1 * num2}}</p>
<p>和:<span ng-bind="num1 + num2"></span></p>
</div>
<div class="test-div" ng-init="firstName='Neo';lastName='Huang'">
<p>FullName: {{firstName + " " + lastName}}</p>
<p>FullName: <span ng-bind="firstName + ' ' +lastName"></span></p>
</div>
<div class="test-div" ng-init="user={userName:'Neo',age:32}">
<p>User: {{user.userName}}</p>
<p>Age: <span ng-bind="user.age"></span></p>
</div>
<div class="test-div" ng-init="colors=['red','green','blue']">
<p>The first color is {{colors[0]}}</p>
<p>The last color is <span ng-bind="colors[2]"></span></p>
</div>
<script type="text/javascript" src="static/js/angular-1.5.8.js"></script>
<script type="text/javascript">
//Angular表达式基本形式:{{expression}} or ng-bind="expression"
//与JS表达式相似,Angular表达式可以包含文本、操作符和变量
//Angular Number,String,Object,Array like JS
//Angular表达式可以写在页面任何地方,Angular对其进行解析并返回结果
//Angular表达式支持过滤(Filter),但不支持条件、循环和异常处理
//初始化变量通常放在Controller中,而不是使用ng-init指令
</script>
</body>
</html>