1

This is my HTML and AngularJs Controller.
When I start the app, the form is filled with data by ng-repeat...

My question and problem is:
When I click on dropdown list I want to call web api with this call and fill form. I call web api and get data from Api but can't fill the form.

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

Angular Controller:

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;
    });
  };

});
2
  • I think you mean table not form. There is no form in your code. Commented Aug 7, 2017 at 20:02
  • what is the response exactly in data ? check to see if allAssists is an array Commented Aug 7, 2017 at 22:33

1 Answer 1

1

I think your problem is that your ng-controller is only surrounding your PULLDOWN, so all the code that displays the page is outside the scope of your controller and doesn't have access to the values. Add a div that contains your app and controller and have it encompass the entire HTML block.

<div ng-app="myapp" ng-controller="PlayerCtrl">
  <div class="dropdown">
  </div>
// The rest of your html
</div>
Sign up to request clarification or add additional context in comments.

1 Comment

That's it. Thanks.

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.