我已经创建了以下自定义按钮组件。点击这个按钮我想重置表单。但是当我执行点击操作时,出现错误:@功能的输入绑定
"ERROR TypeError: Cannot read property 'reset' of undefined"
(因为重置是功能)。
请帮我理解我的错误。
以下是我的代码自定义组件代码
@Input() clearFormData: any;
<button *ngIf="cancelRequired" type="button" class="btn btn-warning pull-right"
(click)="clearFormData()" style="margin-left:0.3em">Cancel</button>
我使用上述组件这样
import { Component, OnInit } from '@angular/core';
import { FormGroup, FormControl, FormBuilder, Validators } from '@angular/forms';
@Component({
selector: 'app-model-driven',
template: '<form-actions [clearFormData] ="clearForm"></form-actions>',
styleUrls: ['./model-driven.component.css']
})
export class ModelDrivenComponent implements OnInit {
clearForm() {
this.form.reset();
}
如果我有多个按钮让我们说“编辑”,我想在我的formaction组件中使用它,我可以这样做吗?像这样? –
hemantmali
是的,你可以输出无限数量的事件发射器(但当然它就像函数的参数,你猜不应该输出超过3,4个事件)。 – Nour