2016-02-21 48 views
3

我是新来的Angular,并试图显示数据使用控制器,但它没有显示..我认为我犯了一些愚蠢的错误,数据不会出现错误。角度数据绑定不显示数据..

这里是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是在这里:

<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> 

回答

3

你应该从ng-repeat当前实例获得的数据在这里它是itemsng-repeat当前实例。

标记

<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> 

当你想从服务器加载数据,你需要使用$http.get调用来检索服务

数据代码

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

+0

谢谢Pankaj ..它的工作.. – kuldeepsingh23

+0

@ kuldeepsingh23很高兴知道这一点。谢谢:) –

+0

哦,是的,我的错误..它对我的工作很好,谢谢.. – kuldeepsingh23