#Event not emitting

7 messages · Page 1 of 1 (latest)

covert hound
#

Hey guys,
Learning angular so go easy on me

I have 3 components inside of my app. 1 parent, 2 children
One is a form where a user submits an "Order" and that order's information gets stored into firebase.
The other component is a "recent orders" display table that gets the orders from firebase and displays the order information for each order.
These components are siblings, so I need to send the event from one child, to the parent, to the other child.

My goal is to update the recent orders table after a new order is submitted. To do this, I have created a custom event inside of my Order Submission component (child) that I am wanting to be received by the parent. However, I cant seem to receive the event inside of the parent component.

relevant code

default.component.html (implements the child, maybe issue with event bind?)

<app-order-input-form (orderCreated)="onOrderCreated($event)" style="display: inline-block;width: 50%;"></app-order-input-form>

default.component.ts (parent, should receive the event)

  onOrderCreated({wasOrderCreated: boolean}){
    console.log("an order was created") //never happens
    //need to refresh table in tasks display
  }

order-input-form-component.ts (submits the order to firebase, should emit an event to parent afterwards)

import { Component, EventEmitter, OnInit, Output } from '@angular/core';
import { HttpClient } from '@angular/common/http';

 @Output() orderCreated = new EventEmitter<{wasOrderCreated:boolean}>();
constructor(private http: HttpClient){}

onSubmitOrder(){
    this.http.post(`REDACTED_FIREBASE.json`, {REDACTED_PAYLOAD}
    ).subscribe(resp => {
      console.log(resp) //firebase order storing works correctly
      //Now need to update orders display

      //Emit order created event
      console.log("trying to emit signal"); //debug. gets logged. 
      this.orderCreated.emit({wasOrderCreated:true});
});

please let me know if theres anything I need to clarify, thank you

red urchin
#

That looks alright, does it log?

covert hound
#

It does! I realized after typing all of this out that I had my order.Created.emit outside of where it should have been

#

Not sure how that happened, I was so confused as to why it wasnt working

#

now its time to figure out how to set up the input so the child can receive the event from parent. ill be back here, im sure

#

thanks for the reply

red urchin
#

np