从角度js资源获取数据

时间:2016-01-22 15:39:29

标签: javascript angularjs rest ionic-framework

我获得了以下格式的资源

d {$promise: Promise, $resolved: false}
$promise: Promise
$$state: Object
__proto__: Object
$resolved: true
result: Array[2]
0: Object
caption: "test"
created_at: "2016-01-13 07:51:09"
description: " wow"
ending_pound: "19"
id: "220"
is_active: "2"
name: "Arsenal cake"
path: "thumb_167926cake.jpg"
price: "1000.00"
starting_pound: "1"
updated_at: "2016-01-13 07:51:09"
__proto__: Object
1: Object
length: 2
__proto__: Array[0]
__proto__: d

我只需从中提取结果。

我收到了以下

的回复
.factory('urgent_cake', function($resource) {
  return $resource('api/urgent-cake');
})

.controller('AppCtrl', function($scope, urgent_cake){
          urgent_cakes_collection= urgent_cake.get();

如何仅从上方对象获得结果

修改

当我尝试

.query()

它出现以下错误

Error: [$resource:badcfg] query
http://errors.angularjs.org/1.4.3/$resource/badcfg?p0=array&p1=object&p2=GET&p3=api%2Furgent-cake
    at ionic.bundle.js:13380

1 个答案:

答案 0 :(得分:1)

您正在以错误的方式使用角度工厂。 如果您不需要自定义构造函数逻辑,则应该更喜欢服务。

所以:

Rec {
doSomething_rjG
doSomething_rjG =
  \ ds_d1o6 ds1_d1o7 ->
    case ds_d1o6 of _ {
      [] -> I# 0;
      : ds2_d1o8 xs_alG -> doSomething_rjG xs_alG ds1_d1o7
    }
end Rec }

main
main =
  >>=
    $fMonadIO
    getContents
    (\ inputdata_apn ->
       case lines inputdata_apn of _ {
         [] -> patError "a.hs:(8,3)-(13,46)|case"#;
         : x_asI xs_asJ ->
           print
             $fShowInt
             (doSomething_rjG
                (map (read $fReadInt) (words x_asI))
                (map (read $fReadInt) (words (head xs_asJ))))
       })

main
main = runMainIO main

在你的控制器内:

module.service('Cake', function($resource) {
    return $resource('/api/cake');
}