Strategies for capturing a customized eventEmitter event

Suppose I have a controller where I'm emitting an event:

@Output() somethingUpdated = new EventEmitter();

and in a method:

***
this.somethingUpdated.emit();
***

In the view, I've added:

(somethingUpdated)="somethingUpdated($event)"

In a directive, I defined:

  @HostListener('somethingUpdated', ['$event'])
  somethingUpdated() {
    console.log('somethingUpdated');
  }

However, this setup doesn't seem to be working.

What am I doing wrong?

Answer №1

Instead of binding the handler to an event on the document, make sure it is receiving events from the specific output source that you have defined.

Remember, the output source is what emits the event in this case.

If you need guidance on using Outputs in Angular (2+), there are plenty of examples available to help you get started in the right direction.

Take a look at the documentation for more information: https://angular.io/docs/ts/latest/cookbook/component-communication.html

Pay special attention to the section titled "Parent listens for child event."

The format used when binding to a document event could be handy if, for example, you wanted a handler to trigger whenever the document was resized.

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

Creating identical dropdown filter options from API in React.js

My dropdown menu is experiencing an issue where it is showing duplicated values from the API. When I receive documents from the backend, some of them have the same name, resulting in duplication in my dropdown list. Here is a snippet of my code: The funct ...

What is preventing me from obtaining the complete base64 string within an array in Ionic 3?

https://i.sstatic.net/xNkwl.pngIs there a way to efficiently convert multiple images at once using a for loop in Ionic 3? Here is the code snippet I have: for (let i in serviceData) { // for(let i=0; i< this.adviceArray.length; i++) { con ...

Discovering the general function types in TypeScript

Currently, I am in the process of developing a function to generate Redux actions (similar to createAction from redux toolkit). My goal is to create a function that can produce action generators based on the types provided to the creator function. const c ...

Why is my root page not dynamic in Next.js 13?

I am currently working on a website using Next.js version 13.0. After running the next build command, I noticed that all pages are functioning properly except for the root page. The issue is that it's being generated as a static page instead of dynami ...

Generate a new subprocess and terminate it once the operation has been initiated

Using child processes in the following way: var exec = require('child_process').exec; var cmd = 'npm install async --save'; exec(cmd, function(error, stdout, stderr) { console.log('stdout: ' + stdout); ...

Creating a dynamic Flash website integrated with a Joomla platform?

Many websites today showcase content that loads and displays with creative effects, all without the need for a page refresh. It's truly magical. Websites like pandora.com, groveshark.com, and hypem.com are perfect examples of sites that have music pla ...

What is the best way to generate a fresh array by utilizing a specific search parameter?

I'm currently exploring ways to create a search box feature. Within my project, I have an array called passengersData that is being fetched from a Redux store. Most examples I've come across regarding search functionality in React involve utili ...

Implementing a filter in React with data fetched from MongoDB

Hey there! I'm encountering an issue while using the code in Project.jsx and ProductList.jsx. Every time I run the code, it gives me this error message: Warning: Each child in a list should have a unique "key" prop. Check the render method of Product ...

Angular progressive web applications (PWAs) continuously fluctuating in their stability,

I have encountered a problem with my Angular application where it never reaches a stable state, as indicated by ApplicationRef.isStable only emitting false once. The Angular docs mention that: the application will never be stable if you start any kind o ...

An issue arises even with the proper configuration in place: "SessionNotCreatedError: session cannot be established as Chrome version needs to fall within the range of 70 to 73."

During my automated testing with selenium-webdriver, I encountered an issue while building a driver using chromedriver. Everything was functioning perfectly until one day, when I ran a test and received the following error message: SessionNotCreatedErro ...

Exploring the wonders of LoopBack querying

Discovering loopback has been an enlightening experience for me. However, as I delve deeper into its functionalities, I've stumbled upon something unexpected. I noticed that when executing queries, such as using the updateAll method, if a parameter i ...

When creating a FlipCard, you may encounter the error message "The object may be null" while using the document.querySelector() method

Having trouble creating a flipcard on Next.js with tsx. The querySelector('.cardflipper') doesn't seem to locate the object and I keep getting this error: "Possibly the object is null". Does anyone know a solution to help my method recognize ...

Update the jQuery click event targeting the specific element

My knowledge of JavaScript and jQuery is limited. I recently purchased a WordPress theme and I am looking to make some customizations to it. On this specific page: https://websitesdevs.com/search-services/ There is a div element that displays the text "A ...

Using an AngularJS filter once the "Apply" button has been triggered

I am facing an issue with a large dataset containing over 4000 items. Whenever I start typing, my browser freezes for up to 15 seconds. To resolve this problem, I want to disable the auto-filter feature and only apply the filter function when a button is c ...

Revamp responsiveness in bootstrap 3 for printing with @media queries

My goal is to disable the responsive features of bootstrap when the event javascript:print() is triggered. This way, I want my webpage to maintain the column grid layout that I have defined, regardless of screen size. One solution suggested in this answer ...

Defining a TypeScript conditional return type that may include undefined

Here is the function I currently have, but unfortunately I encountered the following error: Type '(T & undefined) | { obj: T & ({} | null); }' is not assignable to type 'T extends undefined ? undefined : { obj: T; }'. Type & ...

Error: The document has not been defined - experimenting with vitest

I'm currently working on a Vite project using the React framework. I have written some test cases for my app using Vitest, but when I run the tests, I encounter the following error: FAIL tests/Reservations.test.jsx > Reservations Component > d ...

Choose the default selection for the first item in a populated select using v-model in Vue JS

I am facing a tricky challenge in Vue.js - I need to create two select fields. The first one should be used to select between fruits and vegetables, and based on that selection, the second field should dynamically display the corresponding list of items. ...

Text located in the bottom right corner of the window with the use of JavaScript

Is there a way to replace text at the bottom right of the window, as opposed to the page, so that it remains fixed in the corner of the window? I'm looking to create a "share" link that is always visible. ...

Tips for displaying an alert in JavaScript only when there is content in the error message

I've been assigned the task of adding an alert component that can be closed when the CloseButton is clicked. I have successfully implemented this functionality, but the task description specifies the usage of the finished component as follows: <Err ...