ionic最新版(2.1.8)下如何根据id获取控件

来源:5-2 tab控件

nickylau82

2016-11-19

在最新版下如何实现5-2课程中的功能?根据id获取控件


import  { Component }    from '@angular/core';

import  { HomePage }     from '../home/home';

import  { AboutPage }    from '../about/about';

import  { ContactPage }  from '../contact/contact';

import  { IonicApp }     from 'ionic-angular';


@Component({

templateUrl: 'tabs.html'

})

export class TabsPage {

static get parameters(){

return [[IonicApp]];

}


// this tells the tabs component which Pages

// should be each tab's root Page

tab1Root: any = HomePage;

tab2Root: any = AboutPage;

tab3Root: any = ContactPage;

app     : any = IonicApp;

// app     : any = IonicApp;

constructor(app:IonicApp) {

debugger;

this.app = app;

}


ionViewDidEnter(){

let mainTabs = this.app.getComponent("mainTabs");

mainTabs.select(1);

}

}

代码如上所示,目前是报错说this.app没有getComponent方法,求正确写法和大致语法(文档链接即可)

写回答

1回答

Parry

2016-11-19

http://ionicframework.com/docs/v2/api/components/tabs/Tabs/

<ion-tabs #myTabs>
  <ion-tab [root]="tab1Root"></ion-tab>
  <ion-tab [root]="tab2Root"></ion-tab>
  <ion-tab [root]="tab3Root"></ion-tab>
</ion-tabs>
export class TabsPage {@ViewChild('myTabs') tabRef: Tabs;

ionViewDidEnter() {  this.tabRef.select(2);
 }

}


0
2
nickylau82
需要在上面import ViewChild和Tabs,另外非常感谢!
2016-11-20
共2条回复

Ionic飞速上手的跨平台App开发

以HTML5移动App开发框架Ionic,开发不受平台限制的App

1314 学习 · 640 问题

查看课程