【问题标题】:angular ui router passing just the data from $http get角度 ui 路由器仅从 $http get 传递数据
【发布时间】:2014-05-21 04:18:00
【问题描述】:
resolve: {
  document: function ($stateParams, specialGet, $http) {
    var id = $stateParams.id      
    return specialGet(id)
  },
},

.factory('specialGet', function (Pusher, $q, $http) {
  return function (id) {
    return 
      $http.get('/api/document/'+id)
  }
})

当我将文档注入控制器时,我会得到一个具有这些属性的对象

config: Object
data: Object
headers: function (name) {
status: 200
statusText: "OK"

如何只将数据传递到文档中,而不是返回这个对象,然后必须获取数据?

【问题讨论】:

    标签: javascript angularjs promise angular-ui-router


    【解决方案1】:

    使用 then 方法继续执行 http 承诺,并在那里返回所需的数据。

    resolve: {
      document: function ($stateParams, $http) {
        var nid = $stateParams.id      
        return $http.get('/api/document/'+id).then(function(response) { return response.data; });
      },
    },
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2017-11-27
      • 2018-09-14
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多