我是离子的新手,我不知道我是否做得对。我有两个按钮UserA,UserB,两个按钮共享相同的功能,我需要在用户点击按钮时将用户类型(UserA,UserB)作为参数传递。
这是我的代码:
import {Component} from "@angular/core";
import {IonicPage, NavController, NavParams} from "ionic-angular";
import {BasePage} from "../base/base-page/base-page";
import {Signup} from "../signup/signup";
import {Fields} from "../../enums/fields/Fields";
import {EnumOthers} from "../../enums/EnumOthers";
@IonicPage()
@Component({
selector : 'page-signup-user-type',
templateUrl: 'signup-user-type.html',
})
export class SignupUserType
{
constructor(public navCtrl: NavController, public navParams: NavParams)
{
}
public switchToSignup(userType: number):void
{
switch(userType)
{
case EnumOthers.USER_A:
{
this.navCtrl.push(PageA);
break;
}
case EnumOthers.USER_B:
{
this.navCtrl.push(PageB);
break;
}
default:
{
console.log("Its not working !!!");
break;
}
}
}
}
<ion-header>
<ion-navbar>
<ion-title>User Type</ion-title>
</ion-navbar>
</ion-header>
<ion-content padding>
<button ion-button color="secondary" block (click)="switchToSignup(EnumOthers.USER_A)">A User</button>
<button ion-button color="secondary" block (click)="switchToSignup(EnumOthers.USER_B)">B User</button>
</ion-content>
我正在尝试将这些参数作为 public static readonly 传递,这些参数在我的html(Ionic)中无法访问。我不想传递硬编码的参数。
export class EnumOthers
{
public static readonly USER_A: number = 0;
public static readonly USER_B: number = 1;
}
代码运行成功,但是当我单击按钮时,我收到错误。 Here's the error image