我在工作中使用 Angular 和 ng-repeat,这就是为什么我对它无法渲染感到困惑。这可能是我忽略的一些愚蠢的事情,但我已经花了足够的时间在这上面,值得向其他人寻求提示。
相关位:
JS
.controller('ListCtrl', function($scope, dataAPI){
dataAPI.getIndex().then(function(res) {
console.log('server response', res);
$scope.notes = res;
});
Jade
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]
控制台中没有错误。我检查了范围,并准确地看到了我所期望的内容。数组对象。
最佳答案
问题是我的 dataAPI
方法 getIndex
使用外部库 (q) 来解析请求,而不是将其留给 Angular 的 $http
和 $q
。因此,我需要在设置范围变量后调用 $scope.$apply()
以提醒更改的 Angular 。或者只使用 Angular 内置的 $q
或使用 $http
返回的 Promise。
关于javascript - NG-repeat 不是从示波器中读取数据吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29812728/