Expressions are used to bind application data to HTML. Expressions are written in double brackets like {{expression}}. The behavior in expressions is the same as the ng-bind directive. AngularJS application expressions are pure javascript expressions and output the data they are used there.
AngularJS expression format: {{expression }}
AngularJS expressions can be strings, numbers, operators, and variables
Number operation {{1 + 5}}
String concatenation{{ 'abc' + 'bcd' }}
Variable operation {{ firstName + " " + lastName }}, {{ quantity * cost }}
Object {{ person.lastName }}
Array {{ points[2] }}
AngularJS example
1.Angularjs Numbers
<div ng-app="" ng-init="quantity=2;cost=5"><p>Total price: {{ quantity * cost }}</p></div>The above example output:
Total price: 10
Code comments:
ng-init="quantity=2;cost=5" //Equivalent to var quantity=2,cost=5 in javascript;
The same function can be achieved using ng-bind
<div ng-app="" ng-init="quantity=1;cost=5"><p>Total price: <span ng-bind="quantity * cost"></span></p>//The ng-bind here is equivalent to the innerHTML of the span specified</div>
2. Angularjs string
<div ng-app="" ng-init="firstName='John';lastName='Snow'"><p>Name: {{ firstName + " " + lastName }}</p></div>Output
Name: Jone Snow
3. AngularJS object
<div ng-app="" ng-init="person={firstName:'John',lastName:'Snow'}"><p>The last name is {{ person.lastName }}</p></div>Output
Snow
4. AngularJS array
<div ng-app="" ng-init="points=[1,15,19,2,40]"><p>The third value is {{ points[2] }}</p></div>Output
The third value is 19
The above is the introduction to AngularJS expressions of the AngularJS introductory tutorial introduced to you by the editor. I hope it will be helpful to you!