How to ng-repeat through returned items by calling a function on ng-init?

How to ng-repeat through returned items by calling a function on ng-init?

The live demo example code (HTML + AngularJs) as given below

<html>
<head>
    <script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.2.15/angular.min.js"></script>
    <script>
        var parentApp = angular.module("myApp", []);
        parentApp.controller("MyController", function ($scope) {
            var userDetail = {
                ID: 1,
                Name: 'Anil Singh',
                Age: 30
            };

            $scope.getUsers = function () {
                return userDetail;
            }
        });
    </script>
</head>
<body ng-app="myApp">
    <h2>User Details</h2>
    <div ng-controller="MyController">
        <div ng-init="user = getUsers()">
            <div>ID : {{user.ID}}</div>
            <div>Name : {{user.Name}}</div>
            <div>Age : {{user.Age}}</div>
        </div>
    </div>
</body>

ANIL SINGH

Hey! I'm Anil Singh. I author this blog. I'm Active Blogger, Programmer. I love learning new technologies, programming, blogging and participating the forum discussions more...
My Blogs - http://www.code-sample.com and http://www.code-sample.xyz
My Books - Google Amazon and Flipkart Book Store!

You Might Also Like
Post a Comment
www.code-sample.com/. Powered by Blogger.
ASK Questions
SQL Server NodeJs TypeScript JavaScript Angular SQL Server My Book