如何重置' ss-multiselect -downdown'在angular2

时间:2017-05-17 06:29:38

标签: angular package angular2-forms multi-select ngx-bootstrap

我使用此软件包在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>

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

3 个答案:

答案 0 :(得分:1)

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

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

<强> PLUNKER DEMO

答案 1 :(得分: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];        
    }

答案 2 :(得分:0)

TS:

onReset() {
   this.myForm.reset({
     optionsModel: ['']
   })
}