Перейдите на вкладку c в Ioni c 3 - PullRequest
0 голосов
/ 30 марта 2020

У меня проблемы с выбором индекса вкладок при нажатии кнопки. Я вызываю индекс так же, как в android -tutorial.ts, но он не работает.

Я вызываю функцию в android -tutorial.ts, с функцией startApp () ;

Есть ли другой способ сделать это? Что я делаю неправильно? Надеюсь, вы можете помочь мне!

  • tabs-page.ts
mySelectedIndex: number = 0;
   tabs: Tab[] = [
       {
           page: "NoveltiesPage",
           icon: "icon-novelties"
       },
       {
           page: "BrandsPage",
           icon: "icon-menus"
       },
       {
           page: "LoginPage",
           icon: "icon-user"
       },
       {
           page: "StoresPage",
           icon: "icon-stores"
       },
       {
           page: "AboutPage",
           icon: "custom-hat"
       }
   ];
constructor(public navCtrl: NavController, public events: Events, public alertCtrl: AlertController, public storageProvider: StorageProvider, public pushProvider: PushProvider, public aboutProvider: AboutProvider, private appVersion: AppVersion, public platform: Platform, public deviceProvider: DeviceProvider, public alertProvider: AlertProvider) {
       this.platform.ready().then(() => {
           this.getVersion();
           //Navigate to Login Page on Startup

           this.storageProvider.getUser().then((user: User) => {
               if (user && user.token) {
                   let token = user.token;
                   this.events.publish("user:login", token);
                   this.pushProvider.start();
               }
           });
       });

       this.platform.resume.subscribe(() => {
           this.getVersion();
       });

       this.events.subscribe("user:login", () => {
           this.tabs[2].page = "AccountPage";
       });

       this.events.subscribe("user:logout", () => {
           this.tabs[2].page = "LoginPage";
       });

       this.events.subscribe("user:notification", (data: any) => {
           switch (data.additionalData.type) {
               case "novelty":
                   this.events.publish("novelty:new");
                   this.navCtrl.push("NoveltyPage", {
                       id: data.additionalData.id
                   });
                   break;
               // case "message":
               //  this.events.publish('message:new');
               //  this.navCtrl.push('MessagePage', {
               //      id: data.additionalData.id,
               //  });
               //  break;
               default:
                   this.events.publish("card:update");
                   this.alertProvider.show(data.title, data.message);
                   break;
           }
       });
   }

   getVersion() {
       //get the version of the method
       this.aboutProvider.app().subscribe((data: any) => {
           this.curVersion = data.data;

           //get platform of the Device
           let platform = this.deviceProvider.getPlatform();

           let curV: string = this.curVersion.ios;
           let store: string = this.curVersion.app_ios_url;

           if (platform == "Android") {
               curV = this.curVersion.android;
               store = this.curVersion.app_android_url;
           }

           //get the version of the app
           this.appVersion
               .getVersionNumber()
               .then((data: any) => {
                   let version = data;

                   if (curV > version) {
                       switch (this.curVersion.status) {
                           case "1":
                               this.alertProvider.action(this.curVersion.title, this.curVersion.message, [{ text: "Cancelar" }, { text: "Atualizar", action: "link", link: store }]);
                               break;

                           case "2":
                               this.alertProvider.action(this.curVersion.title, this.curVersion.message, [{ text: "Atualizar", action: "link", link: store }], false);
                               break;

                           default:
                               break;
                       }
                   }
               })
               .catch(e => {});
       });
   }
} 

  • android -tutorial.ts
import { Component, ViewChild } from '@angular/core';
import { Storage } from '@ionic/storage';
import { IonicPage, Slides, NavController, Events, NavParams } from 'ionic-angular';

@IonicPage()
@Component({
  selector: 'page-android-tutorial',
  templateUrl: 'android-tutorial.html',
})
export class AndroidTutorialPage {
    seen: boolean;
    currentIndex: number = 1;
    @ViewChild('slides') slides: Slides;

    constructor(public navCtrl: NavController, public navParams: NavParams, public storage: Storage, public events: Events) {
        this.seen = this.navParams.data.seen;
        if (!this.seen) {
            this.seen = false;
        }
    }

    startApp() {
        this.navCtrl.setRoot('TabsPage', {
         mySelectedIndex : 2
        });
        this.storage.set('hasSeenTutorial', 'true');
    }

    back() {
        this.navCtrl.pop();
    }

    slideChanged() {
        let index = this.slides.getActiveIndex();
        if(index != 4) {
            this.currentIndex = this.slides.getActiveIndex() + 1;
        }
    }

}
  • tabs-page. html
<ion-tabs [selectedIndex]="mySelectedIndex">
   <ion-tab [root]="tab.page" tabIcon="{{tab.icon}}" *ngFor="let tab of tabs"></ion-tab>
</ion-tabs> 

1 Ответ

0 голосов
/ 30 марта 2020

Хорошо, я нахожу способ сделать это.

Вот как я это решил. Мне нужно было иметь возможность передать индекс в tabs-page.ts из android -tutorial.ts

Вот единственное, что я добавил:

    constructor(public navCtrl: NavController, public events: Events, public alertCtrl: AlertController, public storageProvider: StorageProvider, public pushProvider: PushProvider, public aboutProvider: AboutProvider, private appVersion: AppVersion, public platform: Platform, public deviceProvider: DeviceProvider, public alertProvider: AlertProvider, public params: NavParams) {

        this.mySelectedIndex = this.params.get('mySelectedIndex'); <---- THIS IS THE LINE I ADDED

        this.platform.ready().then(() => {
            this.getVersion();
            //Navigate to Login Page on Startup

            this.storageProvider.getUser().then((user: User) => {
                if (user && user.token) {
                    let token = user.token;
                    this.events.publish("user:login", token);
                    this.pushProvider.start();
                }
            });
        });

        this.platform.resume.subscribe(() => {
            this.getVersion();
        });

        this.events.subscribe("user:login", () => {
            this.tabs[2].page = "AccountPage";
        });

        this.events.subscribe("user:logout", () => {
            this.tabs[2].page = "LoginPage";
        });

        this.events.subscribe("user:notification", (data: any) => {
            switch (data.additionalData.type) {
                case "novelty":
                    this.events.publish("novelty:new");
                    this.navCtrl.push("NoveltyPage", {
                        id: data.additionalData.id
                    });
                    break;
                // case "message":
                //  this.events.publish('message:new');
                //  this.navCtrl.push('MessagePage', {
                //      id: data.additionalData.id,
                //  });
                //  break;
                default:
                    this.events.publish("card:update");
                    this.alertProvider.show(data.title, data.message);
                    break;
            }
        });
    }
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...