Difficulty intercepting emitted event from child module in Angular 4

Apologies for my inexperienced inquiry, I am attempting to trigger an event from a child component to a parent component using an @Output and EventEmitter. However, I am facing difficulties in capturing the event in my parent component.

Child Component

@Component({
  selector: 'app-new-attachment',
  templateUrl: './new-attachment.component.html',
  styleUrls: ['./new-attachment.component.css']
})
class NewAttachmentComponent {
  @Input('attachment') attachment: any;
  @Output() doneEditingAttachment:EventEmitter<boolean> = new EventEmitter<boolean>();

  submit() {
    console.log('done editing child');
    this.doneEditingAttachment.emit(true);
  }
}

Parent Component

@Component({
  selector: 'app-new-article',
  templateUrl: './new-article.component.html',
  styleUrls: ['./new-article.component.css']
})
class NewArticleComponent {
   newAttachment: any = {};
   doneEditingAttachment($event) {
     console.log('done editing parent ', $event);
   }
}

I was anticipating to see

done editing child

As well as

done editing parent

However, only done editing child was displayed.

Answer №1

To properly connect to the event of the child element, you must establish a binding using the (eventName) syntax:

<app-new-attachment [attachment]="newAttachment" (doneEditingAttachment)="doneEditingAttachment($event)"></app-new-attachment>

Answer №2

From the feedback received, it appears that you require the following:

<app-edit-attachment [details]="editDetails" (completeAttachmentEdit)="saveChanges()"></app-edit-attachment>

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Exploration of narrowing union types in React with TypeScript

import { Chip } from "@mui/material"; type CourseFilterChipsRangeType = { labels: { from: string; to: string }; values: { from: number; to: number }; toggler: (from: number, to: number) => void; }; type CourseFilterChipsCheckType = { ...

Accessing a webpage by directly pasting the URL into the address bar is functioning properly, but is

I'm facing an issue with accessing files from a vendor's application. When I directly enter the endpoints into the browser's address bar, the file opens up without any problems. However, when I try to access them using jQuery AJAX, I receive ...

Tips for managing a group of checkboxes in Angular 2 RC5

My task involves creating a form where users can edit their magazine subscriptions. Here is the code snippet I am working with: Component: export class OrderFormComponent { subscriptions = [ {id: 'weekly', display: 'Weekly new ...

Using Ajax to delete item from table

I am currently working on populating a table in the View by clicking on items from a dropdown menu. Fortunately, I already have a script that accomplishes this task. Additionally, I have configured it so that when an item in the table is clicked, it is re ...

Tips for efficiently passing a JSON object to a resource using AngularJS

I am looking to integrate a web service that accepts a JSON object with two arrays in a POST request and responds with a JSON object array. Now, I want to make a request to this service from my AngularJS application. Below is the code snippet: wellApp.fa ...

Load a .obj model into a variable using three.js

Just diving into the world of javascript and three.js with a question on my mind. I have successfully loaded a basic .obj file using the following code: var loader = new THREE.OBJLoader(); loader.load( 'test.obj', function ( object ) { scene. ...

The error was thrown at line 800 in the loader.js file of the internal modules

When I ran yarn install in my project folder, I encountered the following error: internal/modules/cjs/loader.js:800 throw err; ^ Error: Cannot find module 'ts-node/register' Require stack: - internal/preload ?[90m at Function.Module._resolveF ...

Troubleshooting duplicate identifier issue when defining a new class in Typescript

Currently, I am in the process of developing a Linked List using Typescript. I have established an INode interface and a node class as a starting point. interface INode<T> { data: T; next: INode<T> | null; } class Node<T> implements ...

Remove outdated cards from a React array

I am facing a complicated situation and require some assistance. Below is the code snippet: The function provided below is used to determine if a credit card has expired or not. It returns true if the card is expired and false if it's valid. const i ...

Issue with Highcharts: Border of stacking bar chart not visible on the right side

When creating a stacking bar chart, I noticed that the rightmost 'box' does not have a border drawn on the right side. Is there a setting or option in Highcharts that can be used to ensure the white border line is drawn around the 75% box in the ...

What is the best way to send an action based on the HTTP method being used?

I've been utilizing NGXS for handling state in my angular project. What would be considered a best practice? Should I make the HTTP call first and then dispatch an action within its subscription? Or should I dispatch the action first and then make t ...

Showing the initials of a user at the top of an SVG using ReactJS

https://i.sstatic.net/oJgXs.png I require the user's initials to be displayed on the avatars as a grey circle with those initials. I have the function ready, but I am unsure of how to implement it in the JSX code for the Dropdown menu (using Semantic ...

Stop users from typing inside a newly inserted element in contenteditable mode

Currently, I am developing a straightforward syntax highlighter that transforms text into DOM elements with specified classes. For example, consider the following: <div contenteditable="true"> Some text. | And some other text. </div> Assum ...

A more efficient approach to coding is to utilize the `insertAdjacentHTML` method instead of creating an entirely new code

I'm attempting to dynamically add new input fields and buttons when a specific button is clicked. <div class="form-group row"> <label>...</label> <div class="col-sm-9 input-group" id="aa"> <input class="form ...

The progression indicator on the mat-sidenav only displays halfway even when it shows 100 percent completed

I have encountered an issue with a simple mat progress bar in a mat side nav and content. When the value is set to 100, it should be completed, but it only fills halfway inside the content. Strangely, it works as expected in the side nav. https://i.sstat ...

Leveraging Classes for Http Observables in Angular 12

Utilizing the power of Angular 12 The backend response received from the HTTP service is structured as follows: Array<{ id: string; title: string; created: string; }> // Service public list(): Observable<Array<Item>> { return ...

Using Node.js, we can create a program that makes repetitive calls to the same API in a

My task involves making recursive API calls using request promise. After receiving the results from the API, I need to write them into an excel file. Below is a sample response from the API: { "totalRecords": 9524, "size": 20, "currentPage": 1, "totalPage ...

Uniquely crafted JSON Ajax loop for dynamic transformations

When making an Ajax JSON call to an API, a variable n is used. The higher the value of the variable and depending on the user, more results are fetched. If the API returns nothing, the JSON value response will be "Nothing found". To handle this scenario ...

Issue with Mongoose schema: Unable to access the property 'password' as it is undefined

I recently attempted to implement passport local authentication based on a tutorial I found. Although everything appeared to be working correctly, I encountered an error when making a request using Postman: [nodemon] 1.18.11 [nodemon] to restart at any ti ...

Setting Default Value for Autocomplete in React

I'm facing an issue with the default value in my autocomplete feature within my React app. Even though I set a default value, when I try to submit the form, it still shows as invalid because it appears to have no value until I manually click on the au ...