3

I am new to Angular and trying to show data using controller but its not showing.. I think i have made some silly mistake and data is not coming without error.

Here is JS:

(function () {
    'use strict';

    var app = angular.module('empapp', []).controller('emplcontroller', ['$scope', function ($scope) {
        $scope.empdatateamdynamo = [
         {
             name: 'name will be here',
             profilepic: 'image will be here',
             designation: 'designation will be here',
             teamname: 'team will be here'
         },

        {
             name: 'name will be here',
             profilepic: 'image will be here',
             designation: 'designation will be here',
             teamname: 'team will be here'
        },

        {
             name: 'name will be here',
             profilepic: 'image will be here',
             designation: 'designation will be here',
             teamname: 'team will be here'
        }
        ]

    }]);

})();

HTML is here:

<body ng-app="empapp">
    <div class="container" ng-controller="emplcontroller">
        <!-- Example row of columns -->
        <div class="row">
            <div class="col-md-4" ng-repeat="items in empdatateamdynamo">
                <h2> {{ empdatateamdynamo.name }}</h2>
                <p> {{ empdatateamdynamo.profilepic }} </p>
                <p> {{ empdatateamdynamo.designation }} </p>
                <p><a class="btn btn-default" href="#" role="button"> {{ empdatateamdynamo.teamname}}</a></p>
            </div>
        </div>
     </div> 
</body>

1 Answer 1

3

You should get data from current instance of ng-repeat here it is items is current instance of ng-repeat.

Markup

<div class="col-md-4" ng-repeat="items in empdatateamdynamo">
    <h2>{{items.name}}</h2>
    <p>{{items.profilepic}} </p>
    <p>{{items.designation}} </p>
    <p>
       <a class="btn btn-default" href="#" role="button"> 
          {{items.teamname}}
       </a>
    </p>
</div>

When you wanted to load data from server, you need to use $http.get call to retrieve data from service

Code

var app = angular.module('empapp', [])
.controller('emplcontroller', ['$scope', '$http', function($scope, $http) {
   $http.get('data.json').then(function(response){
      $scope.empdatateamdynamo = response.data;
   });
}]);

Demo Here

Sign up to request clarification or add additional context in comments.

4 Comments

@kuldeepsingh23 Glad to know that. Thanks :)
Can you please help me if i would like to call this data from external Json?
Seems like working but json is not loading due to some other problem..i will fix this. Thanks again..
@kuldeepsingh23 you could accept answer now. Thanks & cheers :)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.