未捕获的错误:添加导航时,模板在ionic中解析错误

时间:2018-07-07 14:55:14

标签: ionic-framework ionic2

我有一个正在Ionic中构建的应用程序,我尝试从首页向登录页面和注册页面添加导航按钮,但是当我添加功能(click)=”loginPage()”时出现错误。

下面是错误的屏幕截图:

enter image description here

App.module.ts

import { BrowserModule } from '@angular/platform-browser';
import { ErrorHandler, NgModule } from '@angular/core';
import { IonicApp, IonicErrorHandler, IonicModule } from 'ionic-angular';
import { SplashScreen } from '@ionic-native/splash-screen';
import { StatusBar } from '@ionic-native/status-bar';

import { MyApp } from './app.component';
import { HomePage } from '../pages/home/home';
import { LoginPage } from '../pages/login/login';
import { RegisterPage } from '../pages/register/register';

@NgModule({
  declarations: [
    MyApp,
    HomePage,
    LoginPage,
    RegisterPage
  ],
  imports: [
    BrowserModule,
    IonicModule.forRoot(MyApp)
  ],
  bootstrap: [IonicApp],
  entryComponents: [
    MyApp,
    HomePage,
    LoginPage,
    RegisterPage
  ],
  providers: [
    StatusBar,
    SplashScreen,
    {provide: ErrorHandler, useClass: IonicErrorHandler}
  ]
})
export class AppModule {}

home.ts

import { Component } from '@angular/core';
import { NavController, NavParams } from 'ionic-angular';
import { LoginPage } from '../login/login';
import { RegisterPage } from '../register/register';

@Component({
  selector: 'page-home',
  templateUrl: 'home.html'
})
export class HomePage {

  constructor(public navCtrl: NavController, public navParams: NavParams) { 

  }

  loginPage(){
    this.navCtrl.push(LoginPage);
  }

  registerPage(){
    this.navCtrl.push(RegisterPage);
  }

}

和home.html

<ion-content padding class="home"> 
  <ion-grid>
    <ion-row>
      <ion-col col-12 class="div-two">Welcome</ion-col>
    </ion-row>

    <ion-row justify-content-start>
        <ion-col col-6 class="col">
          <div><button ion-button round (click)=”loginPage()”>Login</button></div>
        </ion-col>
        <ion-col col-6 class="col">
          <div><button ion-button round (click)=”registerPage()”>Register</button></div>
        </ion-col>
  </ion-row>

  </ion-grid>
</ion-content>

我已尽力而为,但仍然不知道错误的原因是什么。我是离子新手。

谢谢。

1 个答案:

答案 0 :(得分:1)

您的双引号字符无效。不要使用”loginPage()”,而要使用"loginPage()"

当您直接将一些代码复制到编辑器时,有时会发生这种情况。请注意这一点。