Example : A basic Expression program in AJS to evaluate operation.
<html>
    <head>
        <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.8.2/angular.min.js"></script>
    </head>
    <body ng-app="">
        <p>Sum : {{ 10 + 20 }}</p>
        <p>Product : {{ 5 * 4 }}</p>
    </body>
</html>

Output: 
Sum : 30
Product : 20

-------------  OR  --------------

<html>
    <head>
        <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.8.2/angular.min.js"></script>
    </head>
    <body ng-app="">
        <p>{{ "Hello" + " India World." }}</p>
    </body>
</html>

Output:
Hello India World.

-------------  OR  --------------

<html>
    <head>
        <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.8.2/angular.min.js"></script>
    </head>
    <body ng-app="">
        <div ng-init="x=10; y=20">
            <p>Result : {{ x + y }}</p>
        </div>
    </body>
</html>

Output:
Result : 30

-------------  OR  --------------

<html>
    <head>
        <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.8.2/angular.min.js"></script>
    </head>
    <body ng-app="">
        <div ng-init="colors=['Red', 'Green', 'Blue', 'Yellow', 'Orange']">
            <p>Last Color: {{ colors[4] }}</p>
        </div>
    </body>
</html>

Output: Last Color: Orange

-------------  OR  --------------

<html>
    <head>
        <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.8.2/angular.min.js"></script>
    </head>
    <body ng-app="">
        <div ng-init="marks=75">
            <p>Result : {{ marks >= 40 ? 'Pass' : 'Fail' }}</p>
        </div>
    </body>
</html>

Output:
Result : Pass

-------------  OR  --------------

<html>
    <head>
        <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.8.2/angular.min.js"></script>
    </head>
    <body ng-app="">
        <div ng-init="val1=75;val2=100">
            <p>Result: {{ val1 > val2 ? val1 + " is Larger." : val2 + " is Larger." }}</p>
        </div>
    </body>
</html>

Output:
Result: 100 is Larger.
Example : An AJS program to handle Object Expression.
<html>
    <head>
        <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.8.2/angular.min.js"></script>
    </head>
    <body ng-app="">
        <div ng-init="student={name:'Rani', age:18}">
            <p>Student Name is : {{ student.name }}</p>
            <p>Student Age is : {{ student.age }}</p>
        </div>
    </body>
</html>

Output:
Student Name is : Rani
Student Age is : 18

NB: This is an Object type of Expression.

Loading

Categories: AJS

0 Comments

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.