Angular ng-repeat不显示数据(仅在第一次使用时)

时间:2017-02-03 12:45:55

标签: javascript angularjs

  

更新:这是因为没有设置$ scope.quantity的值

我有3个地方可以重复3个不同的数据源。

我使用3个控制器,只有第一个控制器显示数据。另外两个可以console.log数据,但不显示它。

我真的无法理解为什么一切都适用于第一组数据,但其余部分并不适用,即使所有这些数据的代码几乎相同。

JS

//this is working

function publisherController($scope, $http) {
    //$scope.sortType = 'name'; // set the default sort type
    //$scope.sortReverse = false;  // set the default sort order
    $scope.searchPublisher = '';     // set the default search/filter term

    $http.get("/ServiceProxy.aspx?apiPath=api/path1")
    .then(function (response) {
        $scope.pubNames = response.data;
        console.log(JSON.stringify($scope.pubNames));
    });

    $scope.quantity = 5;
};

// this is not working

var formatController = function ($scope, $http) {
    //$scope.sortType = 'name'; // set the default sort type
    //$scope.sortReverse = false;  // set the default sort order
    $scope.searchFormat = '';     // set the default search/filter term

    $http.get("/ServiceProxy.aspx?apiPath=api/demand/path2")
    .then(function (response) {
        $scope.formatNames = response.data;
        console.log($scope.formatNames);
    });
};

//this is not working

function distributorController($scope, $http) {
    //$scope.sortType = 'name'; // set the default sort type
    //$scope.sortReverse = false;  // set the default sort order
    $scope.searchDistributor = '';     // set the default search/filter term

    $http.get("/ServiceProxy.aspx?apiPath=api/path3")
    .then(function (response) {
        $scope.distributorNames = response.data;
        console.log(JSON.stringify($scope.distributorNames));
    });
};

HTML

<div class="row" ng-app>

    <-- This is working -->

  <div ng-controller="publisherController">
    <table class="table table-bordered table-striped">
         <tbody id="format">
             <tr ng-repeat="roll in pubNames | orderBy:sortType:sortReverse | filter:searchPublisher | limitTo:quantity">
                  <td><input type="checkbox" id="myCheck">{{roll}}</td>
             </tr>
          </tbody>
    </table>
  </div>

    <-- This is NOT working -->

  <div ng-controller="formatController">
    <table class="table table-bordered table-striped">
        <tbody id="format">
            <tr ng-repeat="f in formatNames | orderBy:sortType:sortReverse | filter:searchDistributor | limitTo:quantity">
                <td><input type="checkbox" id="myCheck">{{f}}</td>
             </tr>
        </tbody>
     </table>
  </div>

    <-- This is NOT working -->

  <div ng-controller="distributorController">
    <table class="table table-bordered table-striped">
       <tbody id="distributor">
           <tr ng-repeat="d in distributorNames | orderBy:sortType:sortReverse | filter:searchDistributor | limitTo:quantity">
              <td><input type="checkbox" id="myCheck">{{d}}</td>
            </tr>
        </tbody>

      </table>
   </div>
</div>

0 个答案:

没有答案