Ionic 2添加页面,按钮搜索页面没有任何作用

Ionic 2 Adding Pages, Button to Search page does nothing

本文关键字:作用 搜索 任何 添加 Ionic 按钮      更新时间:2023-09-26

所以我试图添加一个新的页面到我的Ionic应用程序。我已经在命令行中通过"ionic generate page searchpage"创建了文件夹"searchpage"。然后我又加上了……

import { Searchpage } from '../searchpage/searchpage';

到"home"的顶部。

@Component({
  selector: 'page-home',
  templateUrl: 'home.html'
})
export class HomePage {
  constructor(public navCtrl: NavController, public authData: AuthData) {
  }
  logMeOut() {
    this.authData.logoutUser().then( () => {
      this.navCtrl.setRoot(LoginPage);
    });
  }
  searchPage(){
  this.nav.push(Searchpage);
  }
}

然后在home。html中添加按钮…

<button ion-button color="positive" block (click)="searchPage()">
    Search Page
  </button>

按钮出现,但点击时不做任何事情。

请帮助我做错了什么?

您还需要在app.module.ts文件中导入新页面。添加到declarationsentryComponents阵列中。请看下面的例子:

import { NgModule } from '@angular/core';
import { IonicApp, IonicModule } from 'ionic-angular';
import {
  Devices,
} from '../providers';
import { MyApp } from './app.component';
import { Login } from '../pages/login/login';
import { Page1 } from '../pages/page1/page1';
import { Page2 } from '../pages/page2/page2';
@NgModule({
  declarations: [
    MyApp,
    Login,
    Page1,
    Page2,
  ],
  imports: [
    IonicModule.forRoot(MyApp),
  ],
  bootstrap: [IonicApp],
  entryComponents: [
    MyApp,
    Login,
    Page1,
    Page2
  ],
  providers: [
    Devices,
  ]
})
export class AppModule { }