我使用这个包使用了对于我的表单的多选下拉控件: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>
任何帮助将不胜感激。谢谢
对于model-driven
表单,您可以通过调用patchValue
来重置formControl的值。
reset() {
this.myForm.get("optionsModel").patchValue([]); // here multiselect should be reset with an empty array.
}
在按钮单击事件中,您需要设置默认值。
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];
}
TS:
onReset() {
this.myForm.reset({
optionsModel: ['']
})
}