This article mainly introduces the use of the expressions in the detailed angularjs, including the manipulation of various objects such as numbers and strings, and the friends who need them can refer to the following
An expression is used for application data binding to HTML. Expressions are written in double brackets just like {{expression}}}. The behavior in an expression is the same as the ng-bind instruction method. ANGULARJS application expressions are pure JavaScript expressions and output the data they are using there.
Working with numbers
|
<p>expense on books: {Cost * quantity}} rs</p> |
Using strings
|
<p>hello {student.firstname + "" + student.lastname}}!</p> |
Working with objects
|
<p>roll No: {{student.rollno}}</p> |
Using arrays
|
<p>marks (Math): {{marks[3]}}</p> |
Example
The following example shows all of the above expressions.
The testangularjs.html file code is as follows:
<html> <title>AngularJS Expressions</title> <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="http://ajax.googleapis.com/ajax/libs/angularjs/1.2.15/angular.min.js"></script> </body> </html>
Output
Open textangularjs.html in a Web browser. See the results as follows: