ionic [错误]找不到名称'平台'。你的意思是实例成员'this.platform'吗?

时间:2017-05-30 00:37:55

标签: angularjs ionic-framework ionic2 ionic3

我试图创建一个重定向到地图页面的登录页面。我收到错误找不到名字'平台'。你的意思是实例成员'this.platform'吗?在platform.ready()。then(()=> {function。请帮助!我尝试过使用this.platform但也没有用过。谢谢

app.components.ts

import { Component, ViewChild } from '@angular/core';
import { Platform, Nav } from 'ionic-angular';
import { StatusBar, Splashscreen } from 'ionic-native';
import { HomePage } from '../pages/home/home';
import { AboutPage } from '../pages/about/about';
import { RideListPage } from '../pages/ride-list/ride-list';
import { AuthPage } from '../pages/auth/home/home';
import { DataProvider } from '../providers/data';
import { AuthProvider } from '../providers/auth';

export interface PageInterface {
  title: string;
  component: any;
  icon: string;
  logsOut?: boolean;
  index?: number;
  tabComponent?: any;
}

@Component({
  templateUrl: 'app.template.html',
})
export class TaxiApp {
  @ViewChild(Nav) nav: Nav;
  isAppInitialized: boolean = false;
  user: any;
  rootPage: any = AuthPage

  appPages: PageInterface[] = [
    {title: 'Map', component: HomePage, index: 1, icon: 'map'},
    {title: 'Taxi rides', component: RideListPage, index: 2, icon: 'car'},
    {title: 'About', component: AboutPage, index: 3, icon: 'information-circle'},
  ];


  constructor(private platform:Platform,protected data: DataProvider,
    protected auth: AuthProvider) {
    this.user = {
      image: ''
    };
  }

  ngOnInit() {
    this.platform.ready().then(() => {
      this.auth.getUserData().subscribe(data => {
        if (!this.isAppInitialized) {
          this.nav.setRoot(HomePage);
          this.isAppInitialized = true;
        }
        this.user = data;
        this.data.list('pets').subscribe(data => {
          console.log(data);
        });
      }, err => {
        this.nav.setRoot(AuthPage);
      });
      StatusBar.styleDefault();
    }

    // Call any initial plugins when ready
    platform.ready().then(() => {
      // Okay, so the platform is ready and our plugins are available.
      // Here you can do any higher level native things you might need.
      StatusBar.styleDefault();
      Splashscreen.hide();
      // https://github.com/apache/cordova-plugin-inappbrowser
      // The cordova.InAppBrowser.open() function is defined to be a drop-in replacement for the window.open()
      // function. Existing window.open() calls can use the InAppBrowser window, by replacing window.open:
      if ((<any>window).cordova && (<any>window).cordova.InAppBrowser) {
        window.open = (<any>window).cordova.InAppBrowser.open;
      }

    });
  }

  openPage(page: PageInterface) {
    // the nav component was found using @ViewChild(Nav)
    // reset the nav to remove previous pages and only have this page
    // we wouldn't want the back button to show in this scenario
    if (page.index) {
      this.nav.setRoot(page.component, { tabIndex: page.index });
    } else {
      this.nav.setRoot(page.component).catch(() => {
        console.log("Didn't set nav root");
      });
    }
  }
}

0 个答案:

没有答案