Javascript Angularjs承诺对象覆盖属性

Javascript Angularjs承诺对象覆盖属性,javascript,angularjs,Javascript,Angularjs,我在服务中有两个相关的模型,然后有一个外部事件触发带有附加选项的重新查询 Surah服务有许多Ayah: .service 'Surah', (Restangular, Ayah) -> class Surah constructor: (obj) -> for key of obj @[key] = obj[key] getAyahs: (from, to) -> self = @

我在服务中有两个相关的模型,然后有一个外部事件触发带有附加选项的重新查询

Surah服务有许多Ayah:

.service 'Surah', (Restangular, Ayah) ->

    class Surah
      constructor: (obj) ->
        for key of obj
          @[key] = obj[key]

      getAyahs: (from, to) ->
        self = @
        @ayahs = Ayah.all
          surah_id: @id, from: from, to: to
        .then (ayahs) ->
          console.log(ayahs)
          self.ayahs = ayahs
      @new: (id)->
        return Restangular.one('surahs', id).get().then (data)->
          return new Surah(data)

      @all: ->
        return Restangular.all("surahs").getList()



.service 'Ayah', (Restangular, userOptions, utils) ->
    # AngularJS will instantiate a singleton by calling "new" on this function
    class Ayah
      constructor: (obj)->
        for key of obj
          @[key] = obj[key]

      @all: (hash) ->
        Restangular.one('surahs', hash.surah_id).getList 'ayat', 
          content: userOptions.content.join(","), quran: userOptions.quran, audio: userOptions.audio, from: hash.from, to: hash.to
        .then (data)->
          fontFaces = []
          console.log(data)
          ayahs = data.map (ayah) ->
            # The ayah object is returned from Restangular and given all the properties that restangular gives it. For example, you can call
            # ayah.save() or ayah.remove() which will make API calls accordingly. This is power and will be perserved when creating the Ayah object
            return new Ayah(ayah)

          utils.createFontFaces(ayahs)
          return ayahs
在我的控制器中,在选项更改后,我对Ayah服务中的.all执行另一个查询,该服务位于Surah服务的数组和属性中。想象一下:

{ayahs: [A,A,A,A,A,A]}
一旦我在控制器中进行调用,我就会得到一个Promise对象,然后数组就会填充新的Ayahs。这对用户来说不是一个有趣的体验,因为数组中的所有内容都会消失,然后重新填充。我怎样才能避免呢?我如何等待承诺返回,然后更新包含所有Ayah的数组


谢谢

我遇到了一个类似的问题,我可以通过.then中的success函数覆盖要在中存储数据的变量来解决。但我仍然存在这样的问题:它没有显示在视图中,$rootScope不工作