为什么我的 HTML 中没有显示这些获取的数据

Why is this fetched data not being shown in my HTML?

本文关键字:获取 数据 显示 我的 HTML 为什么      更新时间:2023-09-26

我正在从 Parse 数据库中获取一些对象并将它们显示在我的模板中:

.JS:

angular.module('yoApp')
  .controller('downloadsCtrl', function($q, $scope, $rootScope, $http, appService, serviceUpload, fileUpload) {
    $scope.downloads = []
    var Download = Parse.Object.extend('Download')
    var query = new Parse.Query(Download)
    query.find({
      success: function(results) {
        _.each(results, function(result) {
          $scope.downloads.push(result.toJSON())
          console.log($scope.downloads)
          $scope.$apply
        })
      },
      error: function(error) {
        // The object was not retrieved successfully.
        // error is a Parse.Error with an error code and message.
      }
    })
  })

.HTML:

<pre>{{downloads | json}}</pre>

console.log($scope.downloads)输出对象:[Object, Object]

但它们并没有在<pre></pre>之间显示

这是为什么呢?以及如何完成我想要的?

你忘了执行$apply函数。尝试将其更改为$scope.$apply();