如何在angular2中重置'ss-multiselect-dropdown'

问题描述 投票:1回答:3

我使用这个包使用了对于我的表单的多选下拉控件:https://github.com/softsimon/angular-2-dropdown-multiselect

我想在单击Form的Reset Button时重置此控件。

<form [formGroup]="myForm" (ngSubmit)=save()>
    <ss-multiselect-dropdown [options]="myOptions" formControlName="optionsModel"></ss-multiselect-dropdown>
    <button type="reset" class="btn btn-default">Reset</button>
    <button type="submit" class="btn btn-primary">Submit</button>
</form>

任何帮助将不胜感激。谢谢

angular package angular2-forms multi-select ngx-bootstrap
3个回答
1
投票

对于model-driven表单,您可以通过调用patchValue来重置formControl的值。

reset() {
  this.myForm.get("optionsModel").patchValue([]);  // here multiselect should be reset with an empty array.
}

PLUNKER DEMO


0
投票

在按钮单击事件中,您需要设置默认值。

EX:

ngclick(): void {

        this.colours = Array<Colour>();
        this.colours.push(new Colour(-1, 'Please select'));
        this.colours.push(new Colour(1, 'Green'));
        this.colours.push(new Colour(2, 'Pink'));

        this.car = new Car();
        this.car.colour = this.colours[1];        
    }

0
投票

TS:

onReset() {
   this.myForm.reset({
     optionsModel: ['']
   })
}
© www.soinside.com 2019 - 2024. All rights reserved.