简体   繁体   English

当在子组件中发出事件时,父组件中未接收到对象

[英]Object is not receiving in parent component when event is emitted in child component

I trying to send the 2 values to parent component from child component.Event is emitting onSubmit but the object is not receiving values in parent component.我试图将 2 个值从子组件发送到父组件。事件正在发出 onSubmit 但对象没有在父组件中接收值。

// child component

@Output() submitEvent = new EventEmitter < object > ();

//here I am emitting the values

onSubmit() {

  const startdate = moment(this.angForm.get('start_date').value).format('YYYY-MM-DD HH:mm:ss');
  const enddate = moment(this.angForm.get('end_date').value).format('YYYY-MM-DD 23:59:00');
  const obj = {
    startdate: moment(this.angForm.get('start_date').value).format('YYYY-MM-DD HH:mm:ss'),

    enddate: moment(this.angForm.get('end_date').value).format('YYYY-MM-DD 23:59:00')
  }
  this.submitEvent.emit({
    startdate,
    enddate
  });
}
//parent component

<app-filter-panel (submitEvent)="eventrecive(dateobj)"></app-filter-panel>
eventrecive(dateobj) {
  console.log(dateobj);
}

You should use $event as parameter for event emitter handler in the parent component .您应该使用$event作为父组件中事件发射器处理程序的参数。

<app-filter-panel (submitEvent)="eventrecive($event)"></app-filter-panel>
                                             ^^^^^^^  

For EventEmitter events the emitted value is available as $event .对于EventEmitter事件,发出的值可用作$event

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Vue 父组件无法捕获子组件发出的事件 - Vue parent component unable to catch event emitted from the child 用 Jest 测试 Vue:由父组件处理的自定义事件,由子组件发出 - Testing Vue with Jest: custom event handled by parent, emitted by child component Angular 4父组件事件监听器不会被子事件触发 - Angular 4 parent component event listener won't triggered by child emitted event 在子组件(Angular)发出 selectAll 和 unSelectAll 事件后在父组件中获取结果 - get result in parent component after selectAll and unSelectAll event emitted from child (Angular) VueJS:在子组件中触发事件时,在父组件中运行功能 - VueJS: Run function in parent component when event triggered in child component 当子组件中发生onclick事件时,如何重新呈现父组件? - how to rerender parent component when onclick event happend in child component? Vue.js 中的子组件未向父组件发出数据 - Data not emitted from child to parent component in Vue.js 当父组件中发生事件时,如何从子组件更新父组件中的 state - How do you update state in parent component from a child component when an event takes place in the parent component 从父组件到子组件的事件 - Event from parent to child component 发出的事件不会调用 Vue JS 组件中的父方法 - Emitted event doesn't call parent method in Vue JS component
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM