如何使用$ q.all(promises)并在网页上显示回复?

时间:2016-07-05 13:34:38

标签: javascript angularjs node.js

我是Angularjs的新手。我想发送两个GET查询以获取来自两个网址的响应,但我只能从第一个网址获得响应(显示在控制台的屏幕截图中),并且无法在网页上显示响应。

有人可以帮我解决这个问题吗?非常感谢。

screenshot of code

screenshot of console

2 个答案:

答案 0 :(得分:1)

试试这个:

var promises = [];
promises.push($http.get("url1"));
promises.push($http.get("url2"));

$q.all(promises).then(function (data){
    $scope.course = data[0];
    $scope.location = data[1];
}

答案 1 :(得分:1)

您需要将您的网址发送到7-05 08:38:23.956 3055-3068/? A/libc: Fatal signal 6 (SIGABRT), code -6 in tid 3068 (GLThread 131) 07-05 08:38:24.059 1193-1193/? A/DEBUG: *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** 07-05 08:38:24.059 1193-1193/? A/DEBUG: Build fingerprint: 'Android/sdk_google_phone_x86_64/generic_x86_64:6.0/MASTER/2872745:userdebug/test-keys' 07-05 08:38:24.059 1193-1193/? A/DEBUG: Revision: '0' 07-05 08:38:24.059 1193-1193/? A/DEBUG: ABI: 'x86_64' 07-05 08:38:24.059 1193-1193/? A/DEBUG: pid: 3055, tid: 3068, name: GLThread 131 >>> com.example.SanAngeles <<< 07-05 08:38:24.059 1193-1193/? A/DEBUG: signal 6 (SIGABRT), code -6 (SI_TKILL), fault addr -------- 07-05 08:38:24.062 1193-1193/? A/DEBUG: rax 0000000000000000 rbx 00007fd760fbd500 rcx ffffffffffffffff rdx 0000000000000006 07-05 08:38:24.062 1193-1193/? A/DEBUG: rsi 0000000000000bfc rdi 0000000000000bef 07-05 08:38:24.062 1193-1193/? A/DEBUG: r8 0000000000000012 r9 0000000000000003 r10 0000000000000008 r11 0000000000000202 07-05 08:38:24.063 1193-1193/? A/DEBUG: r12 0000000000000bfc r13 0000000000000006 r14 00007fd75d53fb00 r15 000000000000002c 07-05 08:38:24.063 1193-1193/? A/DEBUG: cs 0000000000000033 ss 000000000000002b 07-05 08:38:24.063 1193-1193/? A/DEBUG: rip 00007fd769f3f547 rbp 000000000000000e rsp 00007fd760fbca38 eflags 0000000000000202 07-05 08:38:24.064 1193-1193/? A/DEBUG: backtrace: 07-05 08:38:24.064 1193-1193/? A/DEBUG: #00 pc 0000000000087547 /system/lib64/libc.so (tgkill+7) 07-05 08:38:24.064 1193-1193/? A/DEBUG: #01 pc 0000000000085b11 /system/lib64/libc.so (pthread_kill+65) 07-05 08:38:24.065 1193-1193/? A/DEBUG: #02 pc 000000000002e841 /system/lib64/libc.so (raise+17) 07-05 08:38:24.065 1193-1193/? A/DEBUG: #03 pc 00000000000288fd /system/lib64/libc.so (abort+61) 07-05 08:38:24.065 1193-1193/? A/DEBUG: #04 pc 0000000000002671 /system/lib64/libOpenglSystemCommon.so (QemuPipeStream::writeFully(void const*, unsigned long)+129) 07-05 08:38:24.065 1193-1193/? A/DEBUG: #05 pc 0000000000017c86 /system/lib64/libGLESv2_enc.so 07-05 08:38:24.065 1193-1193/? A/DEBUG: #06 pc 000000000000e47f /system/lib64/libGLESv2_enc.so (GL2Encoder::s_glTexImage2D(void*, unsigned int, int, int, int, int, int, unsigned int, unsigned int, void const*)+159) 07-05 08:38:24.065 1193-1193/? A/DEBUG: #07 pc 000000000000c5ee /system/lib64/egl/libGLESv2_emulation.so (glTexImage2D+94) 07-05 08:38:24.065 1193-1193/? A/DEBUG: #08 pc 00000000000cfb84 /data/app/com.example.SanAngeles-1/lib/x86_64/libsanangeles.so (TextRenderer::SetupGlyphs(std::string, int)+510) 07-05 08:38:24.065 1193-1193/? A/DEBUG: #09 pc 00000000000cfef9 /data/app/com.example.SanAngeles-1/lib/x86_64/libsanangeles.so (TextRenderer::TextRenderer(std::string, std::vector<ProjectLabel, std::allocator<ProjectLabel> >, int)+173) 07-05 08:38:24.065 1193-1193/? A/DEBUG: #10 pc 00000000000cb61a /data/app/com.example.SanAngeles-1/lib/x86_64/libsanangeles.so (appInit+1144) 07-05 08:38:24.065 1193-1193/? A/DEBUG: #11 pc 00000000000ceb49 /data/app/com.example.SanAngeles-1/lib/x86_64/libsanangeles.so (Java_com_example_SanAngeles_DemoRenderer_nativeInit+78) 07-05 08:38:24.066 1193-1193/? A/DEBUG: #12 pc 000000000030e080 /data/app/com.example.SanAngeles-1/oat/x86_64/base.odex (offset 0x1d0000) (void com.example.SanAngeles.DemoRenderer.nativeInit(java.lang.String)+180) 07-05 08:38:24.066 1193-1193/? A/DEBUG: #13 pc 000000000030e5f3 /data/app/com.example.SanAngeles-1/oat/x86_64/base.odex (offset 0x1d0000) (void com.example.SanAngeles.DemoRenderer.onSurfaceCreated(javax.microedition.khronos.opengles.GL10, javax.microedition.khronos.egl.EGLConfig)+423) 07-05 08:38:24.066 1193-1193/? A/DEBUG: #14 pc 0000000073ee31f8 /data/dalvik-cache/x86_64/system@framework@boot.oat (offset 0x1ed6000) 07-05 08:38:24.127 1193-1193/? A/DEBUG: Tombstone written to: /data/tombstones/tombstone_05 07-05 08:38:24.127 1193-1193/? E/DEBUG: AM write failed: Broken pipe## Heading ## 中的数组

export class Service {
    myMethod():Observable<any> {
        return Observable.create((observer:any) => {
        for(let i=0; i<10; i++) {
         observer.next(i);
        }
        if(true==true) {
            // this event I need
            observer.complete();
        } else {
            observer.error(xhr.response);
        }
    }
}

export class Component() {
    // constructor etc.

    doSome() {
        this.service.myMethod()
        // Here I would like to get OnComplete event
          .catch(this.handleError)
          .subscribe((num:any) => {
            console.log(num);
        });
    }
}