📜  AngularJS表达式和JavaScript表达式之间的区别

📅  最后修改于: 2021-05-13 20:27:10             🧑  作者: Mango

Angularjs表达式: AngularJS中的表达式用于将应用程序数据绑定到HTML。表达式由Angular解析,结果返回到写表达式的位置。 AngularJS中的表达式用大括号写成:{{expression}}。它们的行为类似于ng-bind指令:ng-bind =“ expression”。

例子:

3 + 3= {{3 + 3}} 3 - 3 = {{3 - 3}} 3 * 3 = {{3 * 3}} 3 / 3 = {{3 / 3}}

JavaScript表达式:如果一组有效的字面量变量运算符和表达式的结果为一个值,则该表达式为一个表达式。此单个值可以是数字字符串逻辑值(取决于表达式)。在此概念下,有两种类型的表达式。

  • 为变量分配值:
    x = 11
  • 只需具有一个值:
    22 + 11

JavaScript具有以下几种表达式:

  • 算术运算:这些是计算为数字的表达式。
  • 逻辑:这些表达式的计算结果为true或false。
  • 串:这些是将计算得到一个字符的字符串,例如“奇客”或“987”的表达式。

注意:特殊关键字null表示空值。

Angular表达式和JavaScript表达式之间的区别

Parameter Angularjs expression JavaScript expression
Context Angular expressions are evaluated against a scopeobject. JavaScript expressions are evaluated against the global window.
Forgiving In Angular, expression evaluation is forgiving to undefined and null. JavaScript expression try to evaluate undefined properties generates ReferenceError or TypeError.
Control Flow Statements Control flow statements cannot be used in angularjs expressions,i.e,loop,conditional or exception Control flow statements can be used in JavaScript expressions
Function Declarations Angular Expressions do not allow function declaration,not even inside ng-init directive. function declaration is allowed in JavaScript expressions
Bitwise, Comma, And Void Operators In an Angular expression Bitwise, , or void operators cannot be used. You can use Bitwise, , or void operators in an JavaScript expression.
Filter Angular expressions can work with filter JavaScript expressions do not work with filter
One time binding One time binding is supported by AngularJS. To create one time binding use :: expression. JavaScript expression do not allow one time binding.