代码之家  ›  专栏  ›  技术社区  ›  Sireini

setRoot不处理getActiveNavs/getRootNavById

  •  0
  • Sireini  · 技术社区  · 6 年前

    我有办法 changeView()

    方法如下:

    changeView () : void {
        let navCtrl: NavController = this.app.getActiveNavs()[0];
        let hasFetchedDashboardPermission: boolean = this.permissionService.hasFetchedMenuPermission(PermissionId.PAGE_HOME);
        // let testNav;
    
            console.log(this.globalService.isAuthenticated(), !hasFetchedDashboardPermission, navCtrl.getActive() !== undefined)
            if(navCtrl.getActive() !== undefined){
                console.log('active navCtrl', navCtrl.getActive().id)
            }
    
            if (this.globalService.isAuthenticated() && hasFetchedDashboardPermission 
                    && navCtrl.getActive() !== undefined && navCtrl.getActive().id !== 'home' && navCtrl.getActive().id !== 'collegekaart') {
                console.log('setHome');
    
                navCtrl.setRoot('home');
            } else if (this.globalService.isAuthenticated() && !hasFetchedDashboardPermission
                        && navCtrl.getActive() !== undefined && navCtrl.getActive().id !== 'login') {
    
                this.globalService.deleteApiSecurityParams();
    
                console.log('check1', navCtrl.isTransitioning());
                let test = this.app.getActiveNavs();
                test[0].setRoot('login');
    
                this.testNav = this.app.getRootNavById('n4');
                this.testNav.setRoot('login');
    
                // this.app.getRootNav().setRoot('login');
    
                //navCtrl.setRoot('login', null, null, () => { console.log('onDane') })
                // navCtrl.setRoot('login');
            }
        }
    

    1 回复  |  直到 6 年前
        1
  •  0
  •   rguerin    6 年前

    你的控制台输出是什么?哪些日志不显示?

    为什么不在NavController中使用依赖注入,而不是通过 this.app.getActiveNavs()[0]

    尝试将其直接添加到组件构造函数中,如下所示:

    import { NavController } from 'ionic-angular';
    
    export class ItemDetailsPage {
    
        constructor(navCtrl: NavController) {}
    
        changeView () : void {
    
            ... 
    
            if(this.navCtrl.getActive() !== undefined){
                console.log('active navCtrl', this.navCtrl.getActive().id)
            }
    
            ...
        }
    }