-1

我正在研究 Ionic2 + Angular2,我想使用段,所以我使用ngSwitchWhen了,但它不起作用。发生错误。

我该如何使用它?为什么它不起作用?

这是错误消息。

<ion-toolbar>
    <ion-segment [(ngModel)]="menuSelect" color="important">
        <ion-segment-button value="light">
            Light
        </ion-segment-button>
        <ion-segment-button value="sensor">
            Sensor
        </ion-segment-button>
    </ion-segment>
</ion-toolbar> 

<ion-content [ngSwitch]="menuSelect">
    <!--func+ - light-->
    <ion-item *ngSwitchWhen="'light'">
        <ion-list>
            <ion-list-header>
                <ion-label>On/Off</ion-label>
                <ion-toggle (click)="toggleLight()"></ion-toggle>
            </ion-list-header>
        </ion-list>

        <!--light-off-->
        <div [hidden]="lightOn">
            <div class="light-off">Please turn on the light.</div>
        </div>

        <!--light-on-->
        <div [hidden]="!lightOn">
            <ion-list>
                <ion-list-header class="title">
                    Color
                </ion-list-header>
            </ion-list>
            <ion-list>
                <ion-list-header class="title">
                    Brightness
                    <ion-badge>{{brightness}}</ion-badge>
                </ion-list-header>
                <ion-item>
                    <ion-range min="0" max="5" step="1" snaps="true" [(ngModel)]="brightness">
                        <ion-icon range-left small name="sunny"></ion-icon>
                        <ion-icon range-right name="sunny"></ion-icon>
                    </ion-range>
                </ion-item>
            </ion-list>
        </div>
    </ion-item>

    <!--func+ - sensor-->
    <ion-item *ngSwitchWhen="'sensor'">
        <ion-list>
            <ion-list-header>
                <ion-label>On/Off</ion-label>
            </ion-list-header>
        </ion-list>
    </ion-item>
</ion-content>
4

1 回答 1

3

你可以试试这个:

并将您的键盘“ngSwitchWhen”更改为“ngSwitch”

在你的@Component.Html

<div [ngSwitch]="data.type">
  <div *ngSwitchDefault>FORM 1</div>
  <div *ngSwitchCase="'light'">FORM 2</div>
<div *ngSwitchCase="'sensor'">FORM 2</div>
</div>

Bu 在你的@Component.ts 中:

public data:any[]=[];
data.push({type:'light'},{type:'sensor'});
于 2017-11-03T07:00:55.293 回答