我已經創建了以下自定義按鈕組件。點擊這個按鈕我想重置表單。但是當我執行點擊操作時,出現錯誤:@功能的輸入綁定
"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