Answer the question
In order to leave comments, you need to log in
How to pass form TD data (or form itself) from child component to parent?
There is a parent component with a Submit button and a child component with a form (template driven forms).
Well, the question is: How to send the form itself or form.value from the child component to the parent
) but this is necessary for further formation of the model and sending it to the database)
Answer the question
In order to leave comments, you need to log in
parent
<app-child #appChild (submit)="onSubmit($event)"></app-child>
<button (click)="goMessage()">send</button>
@ViewChild('appChild') appChild: ChildComponent;
/** вызов метода потомка */
goMessage() {
this.appChild.send('hello from parent');
}
/** реакция на событие из потомка */
onSubmit(event) {
// проверка данных, заполнение полей, whatever
}
@Output() submit = new EventEmitter<string>();
/** отправим полученную строку обратно наверх */
public send(message: string) {
this.submit.emit(message);
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question