The dumb component isn't receiving the event

I am facing an issue with getting the event from a dumb component. Initially, I thought everything was working fine as the output seemed okay. However, upon changing the event's value, it does not bind to the smart component and no error is displayed.

// planet-data.component.html ( Smart component )

<div class="main">
    <app-loading *ngIf="loading"></app-loading>
    <app-planet-view [pics]="pics" class="fixed" (selected)="onSelect($event)"></app-planet-view>
</div>

// planet-data.component.ts

onSelect(event: Cam) {
    if (event.name === 'CHEMCAM') {
      this.loading = true;
      this.getCamType();
    } else {
      this.loading = true;
      event.name === 'NAVCAM' ? this.getCamType('spirit', 'navcam') : this.getCamType('opportunity', 'fhaz');
    }
  }

// dropdown-menu.component.html ( Dumb component )

<p-dropdown [options]="cameras" [(ngModel)]="selectedCam" placeholder="Select a Cam" optionLabel="name"
            (ngModelChange)="getDisplayCam($event)">
</p-dropdown>

// dropdown-menu.component.ts

getDisplayCam(event: Cam) {
    this.selected.emit(event);
  }

// planet-view.component.html ( Another Dumb component )

<div *ngIf="pics">
  <div *ngFor="let pic of pics.photos">
    <div class="card" style="width: 16rem;">
      <img class="card-img-top" src="{{pic.img_src}}" alt="Card image cap">
      <p>{{pic.earth_date | date}}</p>
    </div>
  </div>
  <h4>{{title}}</h4>
  <app-dropdown-menu></app-dropdown-menu>
</div>

Answer №1

It seems that the selected event is not being emitted in the PlanetViewComponent. Instead, the selected event is raised from the DropdownMenuComponent. If the selected event is not emitted from the PlanetViewComponent, it will not be possible to listen to it in the PlanetDataComponent.

Below is the code snippet from the planet-view.component.html:

<div *ngIf="pics">
  <div *ngFor="let pic of pics.photos">
    <div class="card" style="width: 16rem;">
      <img class="card-img-top" src="{{pic.img_src}}" alt="Card image cap" routerLink="/detail">
      <p>{{pic.earth_date | date}}</p>
    </div>
  </div>
  <!-- Added catching (selected) event -->
  <app-dropdown-menu (selected)="selected.emit($event)"></app-dropdown-menu>
</div>

And here is the code excerpt from the planet-view.component.ts:

@Component({
  selector: 'app-planet-view',
  templateUrl: './planet-view.component.html',
  styleUrls: ['./planet-view.component.sass']
})
export class PlanetViewComponent implements OnInit {

  @Input() pics: Photo;

  // Added @Output() event
  @Output() selected = new EventEmitter<Cam>();
  constructor() {}

  ngOnInit() {
  }
}

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

What is the process for configuring vue.config.js with typescript?

Just starting out with typescript and running into an issue while configuring vue.config.js const webpack = require("webpack"); module.exports = { plugins: [ new webpack.DefinePlugin({ __VUE_I18N_FULL_INSTALL__: true, __ ...

What is the best way to incorporate the useSearchParams hook into props or function arguments?

When I utilize the useSearchParams hook in my component, I encounter an issue where I am unable to type parameters when passing the hook to props or function arguments. import { useSearchParams } from 'react-router-dom'; const urlSearchParamState ...

Ensure that the TypeScript build process includes the addition of the .js extension

When importing a file using import * as test from './dir/file', I noticed that the .js extension is missing in the build output. I prefer the output file to be like this: import * as test from './dir/file.js' The issue at hand is that ...

What is the process for turning off deep imports in Tslint or tsconfig?

Is there a way to prevent deep imports in tsconfig? I am looking to limit imports beyond the library path: import { * } from '@geo/map-lib'; Despite my attempts, imports like @geo/map-lib/src/... are still allowed. { "extends": &q ...

Tips for resolving an Angular 504 Error Response originating from the backend layer

I am currently facing an issue with my setup where I have an Angular application running on localhost (http) and a Spring Boot application running on localhost (https). Despite configuring the proxy in Angular to access the Spring Boot APIs, I keep receivi ...

Is there a way to enforce a mandatory lambda argument?

I am trying to pass a lambda into a function, but I need the lambda to have only one argument. TypeScript correctly generates an error if I provide two parameters to the lambda, however it does not raise any issues if I leave out any arguments altogether ...

What is the best way to interact with the DOM through a service in Angular 2?

My idea is to implement a feature in Angular 2 Apps that can hide and show components. Initially, I considered using *ngIf or ngClass for this purpose, but I found it cumbersome to write the code in this way. So now, I am exploring the possibility of creat ...

When using react-admin with TypeScript, it is not possible to treat a namespace as a type

Encountering issues while adding files from the react-admin example demo, facing some errors: 'Cannot use namespace 'FilterProps' as a type.' Snippet of code: https://github.com/marmelab/react-admin/blob/master/examples/demo/src/orde ...

Guide to integrating a Jquery third-party plugin in Angular 7

Recently, I integrated jQuery and a third-party plugin called "stiffChart" into my Angular 7 project. After installing jQuery and the plugin in my project, I declared them in angular.json file as well. However, when trying to call a method from the plugin, ...

Tips for preventing my component from being duplicated during the development process

I found a helpful guide on creating a JavaScript calendar in React that I am currently following. After implementing the code, I successfully have a functional calendar UI as shown below: // https://medium.com/@nitinpatel_20236/challenge-of-building-a-cal ...

The 'target' property is not found on the type 'KeyboardEventHandler<HTMLInputElement>'

My Visual Studio Code is giving me an error in my onKeyUp function when I try to access the input target and retrieve its value. import React from 'react'; import styles from './styles.module.scss'; export function Step3() { ...

An error is encountered when attempting to retrieve the list using axios

For this project, I am required to fetch a list from the following resource: http://jsonplaceholder.typicode.com/photos The controller setup is as follows: @JsonController('/photo') @Service() export class PhotoController { const ...

Transferring dynamic data to an Angular component's controller

Here's what I currently have: <div *ngFor="let career of careers"> <label>{{career.name}}</label> <input type="checkbox" attr.id="{{career.id}}" (change)="doSomethingWithId($event.target)" </div> This is the TypeSc ...

Having issues with my Angular 4 + MVC web application not functioning properly in Internet Explorer

After creating an application using Angular 4 and MVC, I noticed a problem specifically with Internet Explorer. The application runs smoothly on Chrome, Firefox, and other browsers except for IE. Does anyone have any suggestions on how to resolve this br ...

Resetting Form Status in Angular 4

Recently, I encountered an issue with a modal containing a form that has required fields. Whenever I open the modal, the fields appear empty as expected. However, if I enter some text into a required field and then remove it, causing the field to become in ...

Angular HttpClient Error: Object(...) is throwing a TypeError

Previously, I had nebular admin panel version 5.0.0 with Angular 9 and everything was functioning perfectly. Recently, I upgraded to version 6.0.0 which utilizes Angular 10 by making changes in the package.json. Although the development server is running s ...

Having a problem where the Next.js project is functioning in development mode, but encountering a "module not found" error

After following multiple tutorials to integrate Typescript into my existing app, I finally got it running smoothly in dev mode using cross-env NODE_ENV=development ts-node-script ./server/index.js However, when I execute next build, it completes successfu ...

Injector in Angular is a tool used for dependency injection

I have multiple components; I am using Injector in the constructor for encapsulation import { Component, Injector, OnInit } from '@angular/core'; @Component({ selector: 'app-base', templateUrl: './base.component.html', ...

What is the primary purpose of the index.d.ts file in Typescript?

There are some projects that include all types declarations within the index.d.ts file. This eliminates the need for programmers to explicitly import types from other files. import { TheType } from './somefile.ts' Is this the proper way to use ...

Angular mouseexit event not triggered within *ngFor loop

Is there a solution for the issue where the (mouseleave) directive does not work when generated with *ngFor in Angular? @Component({ selector: 'my-app', template: ` <ng-container *ngFor="let item of hoverdivs; index as i"> < ...