Error: The property 'settDate' is not defined and cannot be read

In Angular, I'm facing an issue when trying to pass data from one component to another on a click event. The structure of my components is as follows:

Parent Component

@Component({
  selector: 'app-reporting-filter',
  templateUrl: './reporting-filter.component.html',
  styleUrls: ['./reporting-filter.component.scss'],
  providers: [ProjectShipmentService]
})

export class ReportingFilterComponent implements DoCheck {

  @ViewChild(TjlShipdateFilterComponent, {static: false})
  private tjl: TjlShipdateFilterComponent;

  finalResult: ShipDateFilterModel[];

  click() {
    this.elem = this.getResultOnFilter(this.firstSelection, this.secondSelection);
      this.tjl.settDate(this.finalResult);
  }
   ........}

Child Component Structure:

Component({
  selector: 'app-tjl-shipdate-filter',
  providers: [ProjectShipmentService],
  templateUrl: './tjl-shipdate-filter.component.html',
  styleUrls: ['./tjl-shipdate-filter.component.scss']
})
export class TjlShipdateFilterComponent implements DoCheck {
 tljShipDate: ShipDateFilterModel[];
  @Input() settDate(e: ShipDateFilterModel[]) {
    this.tljShipDate = e;
  }
......}

Content of reporting-filter.component.html:

      <dxi-item  [ratio]="1">
              <dx-button (onClick)="click()" style="padding: 1vw 3vw 1.5vw 3vw; text-align: center; font-weight: bold;">Filter</dx-button>
      </dxi-item>

However, upon clicking the button and executing 'this.tjl.settDate(this.finalResult);' in the parent component, I encounter the following error:

TypeError: Cannot read property 'settDate' of undefined

We are unsure if there is anything missing here.

https://i.sstatic.net/7yNl1.png

Answer №1

Instead of directly calling methods on the child component, you have the option to pass data and bind it to the Input setter. Remember to include a space between set and Data when implementing this.

 @Input() set Data(e: ShipDateFilterModel[]) {
    this.tljShipDate = e;
  }

In the parent component, create a variable that can be passed down to the child component, like so:


@Component({
  selector: 'app-reporting-filter',
  template: ` 
              <button (click)="click()">Click Me</button>
              <app-tjl-shipdate-filter [data]="tjlData" ></app-tjl-shipdate-filter>
  `,
  providers: [ProjectShipmentService]
})

export class ReportingFilterComponent {
  @ViewChild(TjlShipdateFilterComponent, {static: false})
  private tjl: TjlShipdateFilterComponent;
  private tjlData: any
  click() {
    this.tjlData = 'example data to pass'
  }
}

A functional stackblitz demo can be viewed here: https://stackblitz.com/edit/angular-r24zqd

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

Is there a way to confirm that a method was invoked using the internal testing framework?

Currently, I am utilizing the The Intern test framework to test my web application. My current challenge is verifying whether a method has been called during a test. I have searched for resources that demonstrate how this can be achieved using tools like ...

The texture on the SphereGeometry in Three JS is failing to render correctly

I'm currently using Three JS to create a spherical projection of an image using maptoglobe.com. Here's what I aim to achieve: Here's what I've managed to accomplish so far: The code snippet I'm working with is as follows: th ...

Design a dynamic backdrop using three.js

Hey, I'm currently working on incorporating a background image into my Three JS project. Although the code is functioning properly, the background isn't being displayed. Here is my init function: function init(){ // Creating a new scene scene ...

Is it possible to create a polar grid using Three JS Gridhelper?

While working with Three JS, I was able to add a grid to the scene using the GridHelper. Is there a similar function that can produce a polar grid? This is how the geometry for a 2D Cartesian plane is created (source): var geometry = new THREE.Geometry() ...

Using jQuery to dynamically add a value to a comment string

Is there a way to dynamically include tomorrow's start and end times in the message for the setupOrderingNotAvailable function if today's end time has passed? The current message states that online ordering will be available again tomorrow from 1 ...

Using pdfkit to create a PDF and then returning it as a base64 string from a function

I am attempting to utilize PDFKit to produce a PDF file and then retrieve it as a base64 string. Here is the code snippet I am using: function generatePDFDocument(data){ let doc = new PDFDocument(); var bufferChunks = []; doc.on('readabl ...

Using a nodejs module is causing an error in my code

I am dealing with a module like this: module Net.Server { var socket:dgram.Socket; [...] } Here is my app.ts file: var server:Net.Server = new Server(); However, when I include this line at the beginning of the first file: import dgram = requ ...

Safari experiencing issues with Brightcove's chromeless video player controls

There seems to be an issue with BrightCove's Chromeless player. When hovering over the controls (pause, play, and move to a specific time in the video), they appear but clicking on them causes them to just disappear instead of pausing/playing or movi ...

Implement a bootstrap modal to pop up upon successful form validation using the formvalidation.io

Dealing with a form that can take a significant amount of time to submit due to posting data to multiple APIs is not uncommon. Normally, I display a message in a bootstrap modal asking the user to wait patiently without clicking the back button. This modal ...

Firebase Functions utilizing Realtime Database to update nested child data

Every 10 minutes, a child is created inside my Realtime Database in Firebase through a webservice that sends data via the Rest API. When this data arrives, a function picks it up. The node contains various values, but the important one for further processi ...

Challenges arise with dependencies during the installation of MUI

[insert image description here][1] I attempted to add mui styles and other components to my local machine, but encountered a dependency error. How can I resolve this issue? [1]: https://i.stack.imgur.com/gqxtS.png npm install @mui/styles npm ERR! code ERE ...

Troubleshooting deployment problems in Heroku

Having trouble pushing my application to Heroku. I'm encountering error code h10 and can't seem to resolve it. Could the issue be related to the bcrypt library not being compatible with node 0.12.0? 2015-04-01T02:27:39.716767+00:00 app[web.1]: ...

Having trouble submitting data to a NextJS API route?

I am currently working on a simple form within a NextJS page, where the data is being stored in state: const [bookingInfo, setBookingInfo] = useState({ name: "", email: "", phone: "", }); const handleChange = (e ...

Can content projection be utilized from a child component in Angular?

Keep in mind, this example could be achieved without using content projection. I am just showing a simplified version here. Imagine having a component that displays lists of names in two separate elements: import { Component } from '@angular/core&ap ...

using express routing to display the username or id in the URL

After reviewing some express routing documentation, I attempted to display the logged-in user's username or identification in the URL. However, I am struggling to get the routing working in my server.js file to render the pages even before authenticat ...

The value of the variable in the controller is not being successfully assigned the data that is resolved

//in a PService module this.fetchTypes = function(){ var types = PTypesFactory.retrieve({}); return types.$promise.then(function(result) { console.log(result.groups); return result.groups; }); } ...

The responses for several HTTP POST requests are not being received as expected

I am facing a challenge in retrieving a large number of HTTP POST requests' responses from the Database. When I try to fetch hundreds or even thousands of responses, I encounter issues with missing responses. However, when I test this process with onl ...

Column spilling over with cards

Having a card with a form in it, I wanted to implement a y-scroll bar to control the visibility of the form on the page. However, it seems that the columns are extending beyond the boundaries of the card. .card { box-shadow: 0 4px 8px 0 rgba(0,0,0,0.2 ...

Building a React TypeScript project is successful on Windows, but encounters issues when attempted on a

Currently, I am immersed in a project that involves React TypeScript. Here is the content of the package.json: { "version": "0.1.0", "private": true, "dependencies": { ///... "react": "^16.8.6", "react-scripts-ts": "3.1.0", }, "scri ...

A simple guide on logging into Discord with token using the Selenium library in Python

I created a Python code using the selenium module to log in to Discord using a token number. The token number needs to be added to localStorage, so I used JavaScript code to add it successfully. However, upon checking Application -> localStorage -> h ...