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

Anil Singh is an author, tech blogger, and software programmer. Book writing, tech blogging is something do extra and Anil love doing it. For more detail, kindly refer to this link..

My Tech Blog - https://www.code-sample.com/
My Books - Book 1 and Book 2

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? Reviewed by Anil Singh on 2:22 AM Rating: (5)
www.code-sample.com/. Powered by Blogger.
^