ionicCLI Angular頁面跳轉__angular

來源:互聯網
上載者:User

1、Component中的.html檔案中item添加點擊事件:

<a class="home-menu-item" *ngFor="let item of menuItems" (click)="gotoPage(item)">    <img class="" src="{{item.imgSrc}}">    <span>{{item.subTitle}}</span>  </a>

2、 Component對應的.ts檔案中向home頁面(Page)傳遞事件,傳遞參數:

// 聲明需要外傳的事件@Output()itemAction:EventEmitter<any> = new EventEmitter<any>();// 實現這個方法,方法觸發傳遞事件gotoPage(item:any){    this.itemAction.emit(item);  }

3、 home頁面(Page)的html檔案中,對應使用這個component的標籤中,接收傳遞過來的事件:

<!--接收傳遞過來的事件--><this-component (itemAction)="jumpAction($event)"></this-component>

4、home頁面(page)的.ts檔案中,接收傳遞過來的事件,實現自己的方法:

export class HomePage {  constructor(public navCtrl: NavController) {  }  // 實現對應的方法  jumpAction(menuItem:any) {    console.log(menuItem); // 這個東西就是component中傳遞的資料    this.navCtrl.push(menuItem.destinatePage);  }}

5、如果沒有把新的頁面import到app.module.ts檔案的話,可能會報錯,別忘記(但是後面注釋掉測試一下,又不報錯了)

...import {ComponentsModule} from "../components/components.module";    // <!-- 需要import對應的檔案 -->import {ServiceResourceListPageModule} from "../pages/home/service-resource-list/service-resource-list.module";...@NgModule({  declarations: [    MyApp,    AboutPage,    ContactPage,    HomePage,    TabsPage  ],  imports: [    BrowserModule,    // <!-- imports中添加上對應的頁面模組 -->    ServiceResourceListPageModule,    ComponentsModule,    IonicModule.forRoot(MyApp)  ],  bootstrap: [IonicApp],  entryComponents: [    MyApp,    AboutPage,    ContactPage,    HomePage,    TabsPage  ],  providers: [    StatusBar,    SplashScreen,    {provide: ErrorHandler, useClass: IonicErrorHandler}  ]})export class AppModule {}

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.