Friday, June 26, 2015

AngularJS Expressions using String and Numbers

Expressions in AngularJS can operate on different types of variables / model properties, the evaluation of expressions vary based on the type of variable / property on which the expressions is evaluated.

For example an expression with 2 numbers and a + operator adds the values of the 2 numbers while evaluating the expressions. The same + operator when used with 2 string will do a string concatenation.

The following example shows how to use expressions with numbers and strings

<html ng-app>
<head>
    <meta charset="utf-8" />
    <title>AngularJS - Basic</title>
    <script src="angular.min.js"></script>
</head>
<body>
          <div ng-init="number1=5;number2=4">
                    <p>Sum :<b> {{ number1 + number2 }} </b></p>
          </div>
          <div ng-init="FName='Chris';LName='Charles'">
                   <p>Name :<b> {{ LName + ', ' + FName }} </b></p>
          </div>
</body>
</html>


Output:




Search Flipkart Products:
Flipkart.com

No comments: