导航栏中的ionic2切换可适当使用

导航栏中的ionic2切换可适当使用,ionic2,Ionic2,我正在尝试在导航栏中使用切换来在英语和德语之间切换语言 {{‘目录’|翻译} 这基本上看起来很难看。在导航栏中使用这种切换按钮的正确方法是什么?我知道这已经太晚了,但希望它能帮助任何有类似问题的人 我用的是爱奥尼亚3,这玩意儿对我来说很有用 使用导航栏中的切换按钮: <ion-buttons end> <ion-toggle (ionChange)="onToggle($event)" [(ngModel)]="language"></ion-to

我正在尝试在导航栏中使用切换来在英语和德语之间切换语言


{{‘目录’|翻译}


这基本上看起来很难看。在导航栏中使用这种切换按钮的正确方法是什么?

我知道这已经太晚了,但希望它能帮助任何有类似问题的人

我用的是爱奥尼亚3,这玩意儿对我来说很有用

使用导航栏中的切换按钮:

<ion-buttons end>
  <ion-toggle (ionChange)="onToggle($event)" [(ngModel)]="language"></ion-toggle> // ionChange event will fire every time when you change the toggle state
</ion-buttons>

//每次更改切换状态时,ionChange事件都将触发

如果将其放入
中不起作用,请尝试使用
您可以执行以下操作

html
<ion-buttons end>
  <ion-toggle (ionChange)="onToggle($event)" [(ngModel)]="language"></ion-toggle> // ionChange event will fire every time when you change the toggle state
</ion-buttons>
<ion-header>
    <ion-navbar>
        <ion-title>
            Stackoverflow
        </ion-title>
        <ion-buttons end>
            <button ion-button (click)="toggleClick()">
                <ion-toggle #autoToggle [(ngModel)]="autoRefresh" checked="true"></ion-toggle>
            </button>
        </ion-buttons>
    </ion-navbar>
</ion-header>
import { Component, ViewChild } from '@angular/core';
import { NavController, Toggle } from 'ionic-angular';    
@Component({
    selector: 'page-home',
    templateUrl: 'home.html'
})
export class HomePage {    
    autoRefresh = true;
    @ViewChild('autoToggle') autoToggle: Toggle;
    constructor() {}

    toggleClick() {
        this.autoToggle.checked = !this.autoToggle.checked;
    }
}