Working with JSON

 

<DOCTYPE html>
<html>
    <head>
        <meta CHARSET="UTF-8">
        <script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.4.8/angular.min.js"></script>
    </head>
    <body ng-app="myApp" ng-controller="myCtrl">
        <h2>JSON</h2>
        <fieldset>
            <legend>
                String
            </legend>
            <div ng-init='name = {"first_name":"Shailesh", "last_name" : "Sonare"}'>
                {{name.first_name}} <br/>
                {{name.last_name}}
            </div>
        </fieldset>
        <fieldset>
            <legend>
                Numbers
            </legend>
            <div ng-init='months = {"jan": 1, "feb" : 2}'>
                {{months.jan}} <br/>
                {{months.feb}}
            </div>
        </fieldset>
        <fieldset>
            <legend>
                Objecs
            </legend>
            <div ng-init='result = {employee:{"name": "Shailesh", "age" : 28}}'>
                {{result.employee.name}} <br/>
                {{result.employee.age}}
            </div>
        </fieldset>
        <fieldset>
            <legend>
                Array
            </legend>
            <div ng-init='result = {employee:[{"name": "Shailesh", "age" : 28},{"name": "Mahesh", "age" : 26}]}'>
                {{result.employee[0].name}} <br/>
                {{result.employee[1].age}}
            </div>
            <div ng-init='result2 = {months:["Jan","Feb"]}'>
                {{result2.months[0]}} <br/>
                {{result2.months[1]}}
            </div>
        </fieldset>
    </body>
    <script>
        var app = angular.module("myApp", []);
        app.controller("myCtrl", function($scope) {

        });
    </script>
</html>

 

 

Leave a Reply

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