离子2离子段,如何获得段html?

时间:2016-09-08 17:26:52

标签: javascript angular ionic2 ng-switch

我有这个简单的ion-segment

HTML

<ion-segment [(ngModel)]="type" (ionChange)="selectedTabChanged($event)">
    <ion-segment-button value="a">a</ion-segment-button>
    <ion-segment-button value="b">b</ion-segment-button>
</ion-segment>


 <div [ngSwitch]="type">
    <div *ngSwitchCase="'a'">

        <ion-select #typeSelect (ionChange)="setMake($event)">
            <ion-option value="x">x</ion-option>
        </ion-select> 

    </div>

    <div *ngSwitchCase="'b'">b</div>
</div>

JS

export class MyPage {
    @ViewChild('typeSelect') typeSelect;

    ionViewDidEnter() {
        this.type = 'a';
    }

    selectedTabChanged($event): void {
        console.log(this.typeSelect);
    }
}

期望:

  • 当我点击a时,我希望得到this.typeSelect
  • 当我点击b时,我希望this.typeSelect未定义,因为ion-select仅在a视图中

但是我得到的价值倒退了。我认为当我点击b时,它会从a查找html,反之亦然。

有什么想法吗?

编辑:

看起来如果我在超时中包装更改它工作正常。但问题是,我不知道DOM元素通过un-hidden

获取ngSwitch所需的链接
setTimeout(() => {
    console.log(this.typeSelect);
}, 1000);

0 个答案:

没有答案