飙血推荐
  • HTML教程
  • MySQL教程
  • JavaScript基础教程
  • php入门教程
  • JavaScript正则表达式运用
  • Excel函数教程
  • UEditor使用文档
  • AngularJS教程
  • ThinkPHP5.0教程

AngularJS 表达式

时间:2021-11-22  作者:匿名  

表达式是用来绑定应用程序数据的HTML。 表达式都写在双花括号,如{{表达式}}。 表达式的行为类似于ngbind指令。 AngularJS表达式是纯JavaScript表达式和输出数据。

使用数字

<p>Expense on Books : {{cost * quantity}} Rs</p>

使用字符串

<p>Hello {{student.firstname + " " + student.lastname}}!</p>

使用对象

<p>Roll No: {{student.rollno}}</p>

使用数组

<p>Marks(Math): {{marks[3]}}</p>

例子

下面的示例展示了使用所有上述表达式

testAngularJS.htm

<html>
   <head>
      <title>AngularJS Expressions</title>
   </head>
   
   <body>
      <h1>Sample Application</h1>
      
      <div ng-app = "" ng-init = "quantity = 1;cost = 30; 
         student = {firstname:'Mahesh',lastname:'Parashar',rollno:101};
         marks = [80,90,75,73,60]">
         <p>Hello {{student.firstname + " " + student.lastname}}!</p>
         <p>Expense on Books : {{cost * quantity}} Rs</p>
         <p>Roll No: {{student.rollno}}</p>
         <p>Marks(Math): {{marks[3]}}</p>
      </div>
      
      <script src = "https://www.yangzhiw.cn/static/js/angularjs-1.82/angular.min.js">
      </script>
      
   </body>
</html>

输出

打开文件testAngularJS.htm在web浏览器并查看结果。

Sample Application
Hello Mahesh Parashar!
Expense on Books : 30 Rs
Roll No: 101
Marks(Math): 73
湘ICP备14001474号-3  投诉建议:234161800@qq.com   部分内容来源于网络,如有侵权,请联系删除。