Using Angular to interpolate a string from a Kendo CellClickEvent in a separate component

Within my application, I am working with three main components:

  • Component A: Connects component B and C
  • Component B: Displays a grid of objects
  • Component C: Shows detailed information when a row in the grid of component B is clicked
+---------------------+
|  A                  | 
| +------+  +-------+ |
| |  B   |  |  C    | |
| |      |  |       | |
| +------+  +-------+ |
+---------------------+
export class B{

   @Output() rowClicked= new EventEmitter<{objectOfInterest: any}>();

   public onCellClick (e){
     this.rowClicked.emit(e.dataItem);
   }
}

The KendoUI grid is set up to trigger the event like this:

(cellClick)="onCellClick($event)"
. The event is triggered correctly and contains the dataItem of the clicked row.

In component A's template, I use the following selector:

<B (rowClicked)='C.processData($event)'></B>

Next, we have class C:

export class C{
  public objectOfInterest: any = {};

  constructor(){
    this.objectOfInterest= {'name': 'blaat'};
  }

  public processData = (objOfInterest) => {
    this.objectOfInterest= objOfInterest;
    console.log(this.objectOfInterest.name);
  }
}

Despite the correct printing of the object name in the console, the issue arises when trying to display it in the template of C using string interpolation like this:

Editing {{objectOfInterest.name}}
. No matter what I try, the name of the object is not shown on the screen. I've also attempted:

Editing {{objectOfInterest?.name}}

or

<div *ngIf="someBool">{{objectOfInterest.name}}</div>

but none of these produced the desired output.

I suspect that I may be in the wrong context of this, but when I log this inside the processData function, it correctly displays the objectOfInterest and processData method.

Answer №1

This particular situation appears to be functioning correctly in this context: https://plnkr.co/edit/5Mp4lDuthIJ0SgUEhG2q?p=preview

If you happen to be utilizing the OnPush change detection strategy, the method outlined above will not be effective. In such cases, it is recommended to employ the C component and utilize either the ChangeDetectorRef.markForCheck method or use Input instead of the method while performing any supplementary operations in the setter:

export class C{

  public objectOfInterest: any = {};

  @Input()
  public set objOfInterest(value: any) {
    this.objectOfInterest = value;
    //execute additional actions
  }

}

<B (rowClicked)='objectOfInterest = $event.dataItem'></B>

<C [objOfInterest]="objectOfInterest"></C>

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

I'm curious about why I'm receiving the error "Unable to bind to 'ngFor' since it is not recognized as a property of 'li'. Can someone please explain why this is happening?

The issue is related to the *ngFor directive for nonvegfoodlist app.component.ts import { Component } from '@angular/core'; export class Menu { id : number; name :string; } const veg : Menu[] = [ { id:1 , name:'Rice'}, { id: ...

A guide on using tsc to build a local package

Unique Project Structure I have a unique monorepo structure (utilizing npm workspaces) that includes a directory called api. This api directory houses an express API written in typescript. Additionally, the api folder relies on a local package called @mya ...

Warnings are being generated when Angular 15 features multiple auxiliary routes in a specific module

I currently have 3 different router-outlets set up: primary router-outlet (detail) router-outlet (visited) All the routes are configured within the 'country' module. When you click on a country on the left side, you will see the details on the ...

Tips on using Visual Studio Code to troubleshoot Angular 4 unit tests

I am working on an Angular 4 project with Material design in Visual Studio Code. The setup is done using angular/cli. Currently, I have been writing unit tests using Karma and Jasmine. However, when trying to debug the tests by setting breakpoints, it doe ...

Exploring the concept of converting a data type into an interface using map operations

Recently, I started learning Angular and I've been trying to wrap my head around how mapping from a response to an interface actually works. Let's take a look at the API response I received: [ { "id": 2, "name" : &qu ...

The maximum nested function level has been reached at tsc:1. Consider increasing the FUNCNEST limit

Having an issue while trying to compile a typescript file, encountering the following error: work/gigMax [typescriptMigration●] » tsc src/mutate.ts tsc:1: maximum nested function level reached; increase FUNCNEST? work/gigMax [typescriptMigration●] ...

Posting an array as form data in Angular Typescript: A step-by-step guide

Hello there, I'm currently developing an application using Angular 8 and integrating web.api within .net core 2.2. One of the challenges I encountered is dealing with multi-selectable checkboxes in a form that also includes "regular" inputs and file ...

This object does not have support for the attribute or method "getAttribute"

I've searched for solutions, but nothing seems to work for me and now I'm feeling quite lost. My current setup involves Cordova, Ionic, and Angular 2. Below is the HTML snippet: <ion-col *ngFor="let value of myButtonsFirstRow" width-25> ...

Updating the value of an input field in Angular 2

When I enter 123 in my input field and submit, I want to see 456. Is there a way to change the value of an input programmatically? Here is my HTML code using Ionic2: <ion-textarea [ngFormControl]="message"></ion-textarea> This is the JavaSc ...

What is the best way to create a general getter function in Typescript that supports multiple variations?

My goal is to create a method that acts as a getter, with the option of taking a parameter. This getter should allow access to an object of type T, and return either the entire object or a specific property of that object. The issue I am facing is definin ...

ValidationPipes do not support specific body types

Just a quick question: I'm working on applying a ValidationPipe to a POST endpoint responsible for adding an invoice. Before adding the invoice, I need to validate the body. Here is what I have done: invoice.dto.ts import { ContractorDto } from &apo ...

A static method written in Typescript within an abstract class for generating a new instance of the class itself

Imagine I have abstract class Foo { } class Bar1 extends Foo { constructor(someVar) { ... } } class Bar2 extends Foo { constructor(someVar) { ... } } I want to create a static method that generates an instance of the final class (all construct ...

Incorporate the pdfmake.js file into my TypeScript file

Working on a VSTS web extension and looking to utilize PDFmake.js to generate a pdf. The PDFmake.js file needs to be imported into the node_nodules folder by running npm install pdfmake. To import this JavaScript file into my TypeScript file, I'm fol ...

Issues with identifying the signature of a class decorator arise when invoked as an expression

I've been following this coding example but I'm running into issues when trying to compile it. Any suggestions on how to troubleshoot this error? import { Component } from '@angular/core'; function log(className) { console.log(class ...

How can I prevent the installation of my Ionic 2 application on devices that have been rooted or jailbroken?

I am currently working on a project involving an Ionic 2 and Angular 2 application. I need to implement a feature that checks whether the device is rooted (in the case of Android) or jailbroken (in the case of iOS). I have experimented with various packag ...

Are auto-properties supported in TypeScript yet?

I've heard that properties in Typescript can be defined like they are in C# with automatic setters and getters. However, I have found it difficult to implement properties this way as the intellisense does not support such syntax in Typescript. I tried ...

I am facing a problem with the code for my React login page and router

My form page is built in react and typescript, utilizing JWT tokens on the API side. While there are no issues with the container page, I encountered an error on the index.tsx page where the routers are defined: A TypeScript error occurred in C:/Users/yusu ...

What steps should we take to ensure that the container beside the fixed left navigation bar is responsive?

Currently, I am working on creating a user interface that features a fixed navigation bar on the left hand side and a responsive content window. Here is what I have implemented so far: <div style="width: 15%; float: left; display: inline;"> <na ...

Tips for customizing the appearance of a mat-select chosen item?

Is there a way to modify the color of the selected option text in a mat-select component within an Angular 15 project? .html <mat-form-field> <mat-label>From</mat-label> <mat-select panelClass="mat-select-red"> ...

Tips on submitting JSON data to a server

I need the data to be structured like this {"email":"<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="7f0c3f18121e1613511c1012">[email protected]</a>","password":"1"} but it is currently appearing like this { & ...