承诺调用后应用程序挂起

时间:2019-05-13 09:20:28

标签: angular typescript

代码挂在.subscribe(行

   this.generateSeizeRefNo().then(
      resolve => {
            this.submitBackend(environment.basePrivateUrl + environment.backendRequisition + '/backend/add', 'DRAFT');
        });

}

submitBackend(url, body, action){

    // return new Promise((resolve) => {
    this.http.post(url, body, MediaType.APPLICATION_JSON_VALUE)
        .map((res) => res.json())
        .subscribe(
            (data) => {
                console.log(data);


                    }
                }
                // resolve(null);
            },
            (error) => {
                console.log(error);
            });
    // });
}


generateSeizeRefNo():Promise<any> {

    return new Promise((resolve) => {
        this.http.get(environment.basePrivateUrl + environment.backendRequisition + '/backend/generateSeizeRefNo')
            .retry(3)
            .map((res) => res.text())
            .subscribe(
                (data) => {

                    if (data) {
                        this.seizeRefNo = data;
                    }
                    resolve(data);
                });
    });
}

应用程序应依次调用以下方法。仅当generateSeizeRefNo返回值时,才启动Submitbackend方法 1. generateSeizeRefNo 2. SubmitBackend

0 个答案:

没有答案