簡體   English   中英

拒絕承諾解決即服務

[英]Reject Promise in Resolve as a Service

當我拒絕承諾時,此錯誤將顯示在控制台上。 在控制台中:異常:未捕獲(在承諾中):null error_handler.js:56 ORIGINAL STACKTRACE:錯誤:未捕獲(在承諾中):null

@Injectable()
export class PaymentScheduleResolve implements Resolve<any> {
    constructor(private rtoService: RtoService,
                private rtoActivationService: RtoActivationService,
                private router:Router,
                private toastr: Toastr) {
    }
    resolve() {
        var self = this;
        return new Promise((resolve, reject) => {
            let rtoInfo = self.rtoActivationService.getRtoInfo();
            if (!rtoInfo) {
                reject("null");// This will produce error on console

            }
            else{
                self.rtoActivationService.getPaymentSchedules(rtoInfo.Id, rtoInfo.Data.RtoRentLength)
                    .then((res: any) => {
                        if (res.Response && res.Response.Code === 200) {
                            resolve(res.Response.Data);

                        }
                        else {
                            reject(null);// This will produce error on console
                        }
                    })
                    .catch((err: any) => {
                        console.log(err);
                        reject(null);// This will produce error on console
                    })
            }
        });

    }

只是用

resolve(null);

代替

reject(null);

使用以下命令拒絕解析器。 這會將您重定向到默認路由。

reject({message: err , ngNavigationCancelingError: true});

或者您可以重定向到錯誤頁面

this.router.navigateByUrl('errorPage');
resolve(false);

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM