1

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

单击表单的重置按钮时,我想重置此控件。

<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>

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

4

3 回答 3

1

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

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

柱塞演示

于 2017-05-18T05:16:32.433 回答
0

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

前任:

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];        
    }
于 2017-05-17T07:11:48.003 回答
0

TS:

onReset() {
   this.myForm.reset({
     optionsModel: ['']
   })
}
于 2018-04-06T01:56:33.270 回答