AngularJS入门教程之AngularJS表达式
2019/6/27 22:28:39
本文主要是介绍AngularJS入门教程之AngularJS表达式,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!
表达式用于应用程序数据绑定到HTML。表达式都写在双括号就像{{表达式}}。表达式中的行为跟ng-bind指令方式相同。 AngularJS应用表达式是纯javascript表达式,并输出它们被使用的数据在那里。
AngularJS表达式格式 : {{expression }}
AngularJS表达式可以是字符串、数字、运算符和变量
数字运算{{1 + 5}}
字符串连接{{ 'abc' + 'bcd' }}
变量运算 {{ firstName + " " + lastName }}, {{ quantity * cost }}
对象{{ person.lastName }}
数组{{ points[2] }}
AngularJS例子
1.Angularjs数字
<div ng-app="" ng-init="quantity=2;cost=5"> <p>总价: {{ quantity * cost }}</p> </div>
上例输出:
总价:10
代码注释:
ng-init="quantity=2;cost=5" //相当于javascript里的var quantity=2,cost=5;
使用ng-bind可以实现相同的功能
<div ng-app="" ng-init="quantity=1;cost=5"> <p>总价: <span ng-bind="quantity * cost"></span></p> //这里的ng-bind相当于指定了span的innerHTML </div>
2.Angularjs字符串
<div ng-app="" ng-init="firstName='John';lastName='Snow'"> <p>姓名: {{ firstName + " " + lastName }}</p> </div>
输出
姓名:Jone Snow
3. AngularJS对象
<div ng-app="" ng-init="person={firstName:'John',lastName:'Snow'}"> <p>姓为 {{ person.lastName }}</p> </div>
输出
姓为 Snow
4.AngularJS数组
<div ng-app="" ng-init="points=[1,15,19,2,40]"> <p>第三个值为 {{ points[2] }}</p> </div>
输出
第三个值为 19
以上所述是小编给大家介绍的AngularJS入门教程之AngularJS表达式的相关介绍,希望对大家有所帮助!
这篇关于AngularJS入门教程之AngularJS表达式的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!
- 2024-05-30React Native常用组件-点击组件
- 2024-05-30uniapp+vue3+uv-ui手机端后台OA管理模板
- 2024-05-29Python网络爬虫的时候json=就是让你少写个json.dumps()
- 2024-05-27React Native常用组件-展示组件
- 2024-05-27React Native常用组件-列表组件
- 2024-05-09vue3开发前端表单缓存自定义指令,移动端h5必备插件
- 2024-05-09React Hooks在class组件中的使用方式
- 2024-03-30[OIDC in Action] 2. 基于OIDC(OpenID Connect)的SSO(纯JS客户端)
- 2024-03-29terraform jsonencode
- 2024-03-13vuex-persist