ng-таблица не отображает строки

Мой JavaScript:

$scope.questionsTable = new NgTableParams({}, {
  getData: function($defer, params) {
    return $http.get("/api/questions", {
      params: searchParams
    }).then(function(response) {
      params.settings({
        total: response.data.count
      });
      console.log(response.data.questions);
      return $defer.resolve(response.data.questions);
    });
  }
});

И response.data.questions определенно является массивом. На мой взгляд, у меня

<table class="bordered striped highlight" ng-table="questionsTable">
    <tr ng-repeat="question in $data">
      <td class="top-td">
        <a href="#" ng-click="loadQuestionModal(question.id)">
          {{ question.id }}
        </a>
      </td>
      <td class="top-td">
        <h6 markdown-to-html="question.Instruction.instructionText"></h6>
        <blockquote ng-show="k8englishSubject" markdown-to-html="question.questionText"></blockquote>
        <blockquote markdown-to-html="question.questionText" mathjax-bind="question.questionText" ng-show="k8mathSubject"></blockquote>
      </td>
      <td class="top-td"><ng-include src="'/views/partials/answerList.html'"></ng-include></td>
      <td class="top-td" ng-show="k8englishSubject">
        <a ui-sref="passages.upsert({passageId: question.PassageId})" ng-show="question.PassageId">
          {{ question.Passage.passageTitle }}
        </a>
      </td>
      <td class="top-td">{{ question.level }}</td>
    </tr>
</table>

однако в моей таблице нет отображаемых строк. Что я делаю не так?


person Shamoon    schedule 01.03.2016    source источник
comment
Дело в том, что вы используете промис, который выполняет асинхронный запрос, ваша таблица уже была отрисована, когда промис закончился, и ваш html я не буду обновлять.   -  person Waldemar Neto    schedule 02.03.2016
comment
взгляните здесь stackoverflow.com/questions/23325994/   -  person Waldemar Neto    schedule 02.03.2016


Ответы (1)


Оказывается, мне просто нужно сделать

$scope.questionsTable = new NgTableParams({}, {
  getData: function($defer, params) {
    return $http.get("/api/questions", {
      params: searchParams
    }).then(function(response) {
      params.settings({
        total: response.data.count
      });
      console.log(response.data.questions);
      return response.data.questions;
    });
  }
});

Поскольку $http уже возвращает обещание.

person Shamoon    schedule 02.03.2016