从dialogs.confirm返回observable

问题描述

我有一个应用程序,需要检查上次观看的课程是否大于1。如果是,则必须询问用户是否要导航到该课程。我在解析器中执行此操作,因此直到他们回答问题后,我的页面才会呈现。我似乎无法弄清楚如何从服务调用中返回带有我的xml的可观察对象。如果他们还没有开始,那就在第一课上,它返回xml就很好了,解决方法起作用了,然后转到第一页。但是,当我尝试在dialogs.confirm中返回http请求时,我没有得到正确的数据解析。我试图在对话框上返回of(),我试图在if的if then中返回数据,我试图在if / then中返回of(data)。似乎没有任何东西可以给我有关已解析的ActivatedRouteSnapshot的数据。谁能帮我吗?

if(+route.params['lesson'] === 1) {
            this.playerService.setLessonNum(1);
            this.lessonnum = 1;
            this.playerService.setLessonNum(+route.params['lesson']);
            return this.httpService.getPlayerData({"userId": this.user.username,"corporateId": 1,"classId": this.itemid,"type": "I","AuthToken": this.user.AuthToken,"lesson": this.lessonnum,"class_ID": this.class_ID,"version": this.version})
            .pipe(
                catchError((err: string) => {
                    const errMsg = "There was a network error,please check your connection or try again later";
                    return of(errMsg)
                })
            );
        } else {
            return of(from(dialogs.confirm({
                title: "Bookmark",message: "Would you like to return to your bookmark?",okButtonText: "OK",cancelButtonText: "No",// neutralButtonText: "Neutral text"
            }).then(result => {
                // result argument is boolean
                console.log("Then result from dialog",result);
                this.goToBookmark = result;
                if(this.goToBookmark){
                    console.log("calling player 2 service in resolver",route.params['lesson']);
                    // return this.callService(route.params['lesson']);
                    this.playerService.setLessonNum(+route.params['lesson']);
                    this.lessonnum = +route.params['lesson'] 
                } else {
                    this.playerService.setLessonNum(1);
                    this.lessonnum = 1;
                }
                this.playerService.setLessonNum(this.lessonnum);
                this.httpService.getPlayerData({"userId": this.user.username,"version": this.version})
                .pipe(    
                    map((data) => {this.xml = data}),catchError((err: string) => {
                    const errMsg = "There was a network error,please check your connection or try again later";
                    return of(errMsg)
                    }));
                    return this.xml;
                })))}

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)