Ionic2无法获得离子段ngmodel值

时间:2017-07-15 14:51:14

标签: angular ionic-framework ionic2

我有一个类似下面的HTML:

<ion-content>
<ion-segment [(ngModel)]="authorize">
<ion-segment-button value="register">
   Register
</ion-segment-button>
<ion-segment-button value="login">
   Login
</ion-segment-button>
</ion-segment>
<div [ngSwitch]="authorize">
<ion-list *ngSwitchCase="'register'">
  <p>register</p>
</ion-list>
<ion-list *ngSwitchCase="'login'">
  <p>login</p>
</ion-list>    
</div>
</ion-content>

我想选择以下ts中的一个片段:

import { Component } from '@angular/core';
import { NavController } from 'ionic-angular';
import { NavParams } from 'ionic-angular';

@Component({
 selector: 'page-login',
 templateUrl: 'login.html'
})
export class LoginPage {
  constructor(public navCtrl: NavController, private navParams: NavParams) {
    let sel = navParams.get('sel');
    if(sel == 'register')
      authorize: string = "register";
else if(sel == 'login')
  authorize: string = "login";
  }
}

但是当我编译时出现以下错误:

  

“LoginPage”类型中不存在“'authorize'属性。

有谁知道如何解决这个问题?

1 个答案:

答案 0 :(得分:1)

authorize放在班级

export class LoginPage {

authorize:string;

  constructor(public navCtrl: NavController, private navParams: NavParams) {
    let sel = navParams.get('sel');
    if(sel == 'register'){
        this.authorize= "register";
    }else if(sel == 'login'){
        this.authorize= "login";
    }
  }
}

错误是因为变量selregisterlogin不匹配会怎样。