【发布时间】:2018-12-11 10:29:30
【问题描述】:
我有一个包含多个输入字段的表单,我想在使用@Input 和@Output 单击提交按钮时输出填写在表单中的数据以显示在我的页面中 在我的 form-template.component.ts-
export class FormTemplateComponent implements OnInit, AfterViewInit {
model: any = {};
task: Array<any> = [];
@Output() valueChange = new EventEmitter<any>();
onSubmit() {
this.task.push({Name: this.model.name, Phone: this.model.phone,
Email: this.model.email, Password: this.model.password});
this.valueChange.emit(this.task);
}
现在在我的 app.component.html 中添加了这个
<app-form-output-io (valueChange)="displayArray($event)"></app-form-output-io>
现在,在 app.component.ts 中定义 displayArray($event)
outputTableArray: any=[];
displayArray(theArray){
this.outputTableArray=theArray;
console.log(theArray);
console.log('the array');
}
所以,什么都没有发生!
【问题讨论】:
-
app-form-output-io是FormTemplateComponent的选择器? -
您的消息是空的还是根本没有消息?如果没有消息,您是否检查过您的提交事件?
-
@Output() valueChange = new EventEmitter
(); -
@Eliseo 可以,谢谢。
标签: angular typescript angular6 angular-components angular-forms