2016-02-21 47 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