• #AngularJS#表达式


    表达式

    AngularJS 表达式写在双大括号内:{{ expression }}

    AngularJS 表达式把数据绑定到 HTML,这与 ng-bind 指令有异曲同工之妙。

    AngularJS 将在表达式书写的位置"输出"数据。

    AngularJS 表达式 很像 JavaScript 表达式:它们可以包含文字、运算符和变量。

    实例{{ 5 + 5 }}{{ firstName + " " + lastName }}

    源码

    <!DOCTYPE html>
    <html>
    <body>
    
    <div ng-app="">
      <p>我的第一个表达式: {{ 5 + 5 }}</p>
    </div>
    
    <script src="http://apps.bdimg.com/libs/angular.js/1.4.6/angular.min.js" rel="external nofollow" rel="external nofollow" rel="external nofollow" ></script>
    
    </body>
    </html>
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12

    数字

    AngularJS数字就像JavaScript数字

    源码

    <div ng-app="" ng-init="quantity=1;cost=5">
    
    	<p>总价: {{ quantity * cost }}</p>
    
    </div>
    
    • 1
    • 2
    • 3
    • 4
    • 5

    使用ng-bind的相同实例:

    <div ng-app="" ng-init="quantity=1;cost=5">
        <p>总价: <span ng-bind="quantity * cost"></span></p>
    </div>
    
    • 1
    • 2
    • 3

    使用 ng-init 不是很常见。

    字符串

    AngularJS字符串就像JavaScript字符串

    源码

    <div ng-app="" ng-init="firstName='John'; lastName='Doe'">
        <p> 姓名:{{ firstName + '' + lastName }}</p>
    </div>
    
    • 1
    • 2
    • 3

    使用ng-bind的相同实例

    <div ng-app="" ng-init="firstName='Jhon'; lastName='Doe'">
        <p>姓名: <span ng-bind="fistName + '' + lastName"></span></p>
    </div>
    
    • 1
    • 2
    • 3

    对象

    AngularJS的对象就像JavaScript的对象

    源码

    <div ng-app="" ng-init="person={firstName: 'sujuan',lastName: 'zhou'}">
            <p>姓名为:{{person.lastName + person.firstName}}</p>
            <hr>
            <!-- ng-bind -->
            <p>姓名为:<span ng-bind="person.lastName + person.firstName"></span></p>
    </div>
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6

    数组

    AngularJS的数组就像JavaScript的数组

    源码

    <div ng-app="" ng-init="points=[1,25,36,22]">
            <p>points的第三个值是: {{points[2]}}</p>
    
            <hr>
    
            <p>points的第三个值是: <span ng-bind="points[2]"></span></p>
    </div>
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7

  • 相关阅读:
    web容器之NGINX
    win10搭建Selenium环境+java+IDEA(3)
    Na小工具(电脑)
    世界各国自然资源租金面板数据
    狂神。SpringBoot员工管理系统项目练习。
    windows下mysql的数据主主同步
    【SpringCloud微服务项目实战-mall4cloud项目(3)】——mall4cloud-auth
    android 判断是否打开了蓝牙网络共享
    SQLite简单介绍
    【第十一章 Set接口概述,HashSet,LinkedHashSet,TreeSet】
  • 原文地址:https://blog.csdn.net/qq_42592823/article/details/125634003