2017-08-07 130 views
1

這是我的HTML和AngularJs控制器。
當我啓動應用程序,表格由ng-repeat填充數據...用angularJs填寫表格

我的問題,問題是:
當我點擊下拉列表,我想調用Web API使用該調用,並填寫形成。我打電話給web api並從Api獲取數據,但無法填寫表單。

<div class="dropdown" ng-app="myapp" ng-controller="PlayerCtrl"> 
    <button class="btn btn-primary dropdown-toggle" type="button" data-toggle="dropdown">Insert 
    <span class="caret"></span></button> 
    <ul class="dropdown-menu"> 
    <li><a ng-click="Testmetod('2018')" >2018</li> 
    <li><a ng-click="Testmetod('2017')" >2017</li> 
    <li><a ng-click="Testmetod('Previous')" >Previous</li> 
    </ul> 
</div> 

    <div class="lisstatistic"> 
    <section> 
     <div class="tbl-headerStat"> 
     <table cellpadding="0" cellspacing="0" border="1"> 
      <thead> 
      <tr> 
       <th style="width :20%;">Pos</th> 
       <th style="width :60%;">Player</th> 
       <th style="width :20%;">AST</th> 
      </tr> 
      </thead> 
     </table> 
     </div> 
     <div class="tbl-contentStat"> 
     <table cellpadding="0" cellspacing="0" border="0"> 
      <tbody> 
      <tr ng-repeat="dataModel in allAsists"> 
       <td style="width :20%; padding-top: 5px;" >{{dataModel.AstPosition}}</td> 
       <td ng-if = "dataModel.Player.Status == 0" style="width :60%; color:red; padding-top: 5px;" >{{dataModel.Player.FullName}}</td> 
       <td ng-if = "dataModel.Player.Status == 1" style="width :60%; padding-top: 5px;" >{{dataModel.Player.FullName}}</td> 
       <td ng-if = "dataModel.Player.Status == 0" style="width :20%; color:red; padding-top: 5px; text-align:center;" >{{dataModel.Asists | number:0}}</td> 
       <td ng-if = "dataModel.Player.Status == 1" style="width :20%; padding-top: 5px; text-align:center;" >{{dataModel.Asists | number:0}}</td> 
      </tr> 
      </tbody> 
     </table> 
     </div> 
    </section> 
</div><div class="lisstatistic"> 
    <section> 
     <div class="tbl-headerStat"> 
     <table cellpadding="0" cellspacing="0" border="1"> 
      <thead> 
      <tr> 
       <th style="width :20%;">Pos</th> 
       <th style="width :60%;">Player</th> 
       <th style="width :20%;">PTS</th> 
      </tr> 
      </thead> 
     </table> 
     </div> 
     <div class="tbl-contentStat"> 
     <table cellpadding="0" cellspacing="0" border="0"> 
      <tbody> 
      <tr ng-repeat="dataModel in allPoints"> 
       <td style="width :20%; padding-top: 5px;" >{{dataModel.PtsPosition}}</td> 
       <td ng-if = "dataModel.Player.Status == 0" style="width :60%; color:red; padding-top: 5px;" >{{dataModel.Player.FullName}}</td> 
       <td ng-if = "dataModel.Player.Status == 1" style="width :60%; padding-top: 5px;" >{{dataModel.Player.FullName}}</td> 
       <td ng-if = "dataModel.Player.Status == 0" style="width :20%; color:red; padding-top: 5px; text-align:center;" >{{dataModel.Points | number:0}}</td> 
       <td ng-if = "dataModel.Player.Status == 1" style="width :20%; padding-top: 5px; text-align:center;" >{{dataModel.Points | number:0}}</td> 
      </tr> 
      </tbody> 
     </table> 
     </div> 
    </section> 
</div> 

角控制器:

app.controller('PlayerCtrl', function ($scope, $http, ApiCall) { 

    var result = ApiCall.GetApiCall("nba", "GetRebounds/2000").success(function (data) { 
     //var data = $.parseJSON(JSON.parse(data)); 
     $scope.allRebounds = data; 
    }); 

    $scope.Testmetod = function(year) { 
    var result = ApiCall.GetApiCall("nba", "GetAsists" + '/' + year).success(function (data) { 
     $scope.allAsists = data; 
    }); 
    }; 

}); 
+0

我認爲你的意思是'表'不是形式。代碼中沒有任何表單。 –

+0

數據中的準確響應是什麼?檢查allAssists是否是一個數組 – Shahzad

回答

1

我覺得你的問題是,你的NG-控制器只圍繞你的下拉菜單中,因此所有顯示的頁面的代碼是控制器的範圍之外,並沒有按無法訪問這些值。 添加一個包含您的應用和控制器的div,讓它包含整個HTML塊。

<div ng-app="myapp" ng-controller="PlayerCtrl"> 
    <div class="dropdown"> 
    </div> 
// The rest of your html 
</div> 
+0

就是這樣。謝謝。 – NeshaSerbia