Ng-repeat是不是从范围读取?

时间:2015-04-23 02:49:16

标签: javascript angularjs pug

我使用角度&在工作中重复,这就是为什么我为什么不能渲染而感到困惑的原因。这可能是我忽视的愚蠢行为,但我已经花了足够的时间在上面,因此要求别人提供一些暗示。

相关位:

JS

  .controller('ListCtrl', function($scope, dataAPI){
    dataAPI.getIndex().then(function(res) {
      console.log('server response', res);
      $scope.notes = res;
    });

  h1 Hello this is the list
  div(ng-controller='ListCtrl')
    div(ng-repeat='note in notes')
      div {{ note.dist_path }}

加载数据的控制台日志(对象数组)

server response [Object, Object, Object, Object]

控制台中没有错误。我检查范围,我看到了我期望的确切内容。数组的对象。

1 个答案:

答案 0 :(得分:1)

问题在于我的dataAPI方法getIndex正在使用外部库(q)来解析请求,而不是将其留给角色$http和{ {1}}。所以我需要在设置范围变量后调用$q以警告更改的角度。或者只使用$scope.$apply()中内置的角度,或使用$q返回的承诺。