【问题标题】:Set value of ion-input to null when ion-checkbox is unchecked without [(ngModel)] angular 2 ionic 2在没有 [(ngModel)] 的情况下取消选中 ion-checkbox 时,将 ion-input 的值设置为 null angular 2 ionic 2
【发布时间】:2018-05-14 04:46:07
【问题描述】:

我想在取消选中 ion-checkbox 时清空 ion-input 值。

<ion-item>
    <ion-label class = "Price">Fixed Price
        <ion-checkbox #FixedPrice></ion-checkbox>
    </ion-label>
</ion-item>
<ion-item>
    //I want to do something like that.
    <ion-input [value = ""]  = "!FixedPrice.checked"></ion-input>
    // i.e when I uncheck the ion-checkbox it should set the value of ion-input to "".
</ion-item>

如果您需要其他信息,请告诉我。

【问题讨论】:

    标签: checkbox ionic2 angular2-forms


    【解决方案1】:

    您可以通过(tap) 事件来实现这一点。

    *.compnent.html

    <ion-item>
        <ion-label class = "Price">Fixed Price
            <ion-checkbox [(ngModel)]="fixedPrice" (tap)="fixedPriceCheck()"></ion-checkbox>
        </ion-label>
    </ion-item>
    <ion-item>
        <ion-input [(ngModel)]="priceInput"></ion-input>
    </ion-item>
    

    *.component.ts

    public fixedPrice: boolean = false;
    public priceInput: string = '';
    
    public fixedPriceCheck(): void {
        if (!this.fixedPrice) {
            this.priceInput = '';
        }
    }
    

    【讨论】:

    • 我知道这种方法。但我想要它没有 [(ngModel)]。
    猜你喜欢
    • 2017-05-29
    • 1970-01-01
    • 1970-01-01
    • 2018-06-05
    • 2021-05-23
    • 2018-01-15
    • 2018-10-28
    • 1970-01-01
    • 2017-06-02
    相关资源
    最近更新 更多