TS2339: The property 'batch' is not found on the 'BatchDashboardComponent' type, please update your code

Currently, I'm attempting to showcase some test data on a table within this pug file.

  .container
    p-table([value]="batches")
      ng-template(pTemplate="header")
        tr
          th Batch ID
          th Batch Start
          th Batch End
          th Mismatched Customers
          th Customers Evaluated
      ng-template(pTemplate="body" let-batch='')
        tr
          td {{batch.batchId}}
          td {{batch.batchStart}}
          td {{batch.batchEnd}}
          td {{batch.quantityMismatched}}
          td {{batch.quantityEvaluated}}

However, I am encountering errors stating that the 'batch' property does not exist on type 'BatchDashboardComponent'

Here is my typescript file:

import { Component, OnInit } from '@angular/core';
import { BatchData } from '../../util/data';
import { BATCHES } from '../../util/mock-data';
import { BatchService } from '../../services/batch/batch.service';

@Component({
  selector: 'batch-dashboard',
  templateUrl: './batch-dashboard.component.pug',
  styleUrls: ['./batch-dashboard.component.scss'],
  providers: [BatchService]
})
export class BatchDashboardComponent implements OnInit {
  batches: BatchData[];

  constructor(){

  }

  ngOnInit(){
    this.batches = BATCHES;
    console.log(this.batches);
  }
}

The mock data structure of type BatchData defined as:

export interface BatchData {
  batchId: number,
  batchStart: string,
  batchEnd: string,
  quantityMismatched: number,
  quantityEvaluated: number
}

If you have any insights into why I'm facing this issue, please share them. Thanks in advance!

EDIT: I've also experimented with these approaches but they didn't work:

.centered-col-8
  .container
    p-table([value]="batches")
      ng-template(pTemplate="header")
        tr
          th Batch ID
          th Batch Start
          th Batch End
          th Mismatched Customers
          th Customers Evaluated
      ng-template(pTemplate="body" let-batch)
        tr
          td {{batch.batchId}}
          td {{batch.batchStart}}
          td {{batch.batchEnd}}
          td {{batch.quantityMismatched}}
          td {{batch.quantityEvaluated}}
.centered-col-8
  .container
    p-table([value]="batches")
      ng-template(pTemplate="header")
        tr
          th Batch ID
          th Batch Start
          th Batch End
          th Mismatched Customers
          th Customers Evaluated
      ng-template(pTemplate="body" let-batch [ngForOf]="batches")
        tr
          td {{batch.batchId}}
          td {{batch.batchStart}}
          td {{batch.batchEnd}}
          td {{batch.quantityMismatched}}
          td {{batch.quantityEvaluated}}

Answer №1

After some troubleshooting, I believe I have resolved the problem by including this code snippet in my TypeScript file which effectively eliminated the errors.

batch: BatchData;

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

Issue with change detection in Angular 5 when providers are provided with useValue

Within my Angular 5 app, I have implemented a unique approach to connecting components and services. This is achieved through a 'broker' object which utilizes RXJS Subject fields to facilitate communication and command execution within the system ...

Create a new data structure that generates a different type of generic data

I'm struggling to find the right words, so I'll provide an illustration: // For observables type UnwrappedObs<T> = T extends Observable<infer T> ? T : never; // For promises type UnwrappedPro<T> = T extends PromiseLike<infer ...

Issue with upgrading node from 12v to 16v: Trying to access a property that does not exist, specifically 'splice', within a circular dependency in module exports

After upgrading the node version from 12 to 16, we encountered a debugging console error. The 'Promises' are failing to resolve following this error, leading to the termination of further execution. (node:28112) Warning: Accessing non-existent p ...

Exploring the world of mocking tests using Jest and inputs

Is there a way to create a jest test specifically for this function? const input = require('prompt-sync')(); export function choices(): void { const choice = input("Choose a letter"); if (choice === "a") { con ...

Protractor failing to detect altered navbar post-login during e2e testing

During an e2e test run, the computer attempts to log in with a specified email and password using the Google login API. Upon successful login, the navbar switches from displaying "Login" to "Logout". I have been trying to wait for the Logout button to appe ...

Struggling to capture the changing variables in Angular 8

Hey there, I've been working on a basic Angular app to sharpen my skills, but I'm facing an issue with detecting changes in a service variable. To explain further, I have a component that's subscribed to a variable from a service. However, ...

The module '@angular/cdk/testing' cannot be located

Currently, I am experimenting with the createKeyboardEvent function provided by @angular/cdk/testing to simulate keyboard events: const ENTER_EVENT = createKeyboardEvent('keydown', ENTER, inputNativeElement); Despite installing @angular/cdk usi ...

Tips on utilizing the hide and show feature for dynamic values in Ionic 3 to conceal certain values

I am looking for a way to dynamically hide and show element values, but currently the values are being displayed in both the hidden and shown states (as seen in the second image). Access the project via this Stackbiltz URL Does anyone have any suggesti ...

Troubleshooting Angular: Dealing with Cross-Origin Resource Sharing (CORS) issue

I am currently facing an issue with posting data to elasticsearch from my service. The CORS policy is blocking the action and even after attempting to use a proxy script, the error persists. Can anyone offer assistance in resolving this? Here is the proxy ...

Export a TypeScript type dynamically

I'm currently developing an application and I have a query regarding dynamically exporting a type. My API call retrieves a list of categories. const getCategories = async () => { const fetchedCategories = await axios.get(uri) // Expected outp ...

Utilize the parameter to reach a pre-established offspring

Below, I am attempting to use the parameter ('selected') to invoke a set style function with the passed string parameter (onClick('firstheader')) I hope my point was explained clearly. @ViewChild('firstheader', { static: f ...

How can I implement a master-detail view in Angular 2?

Update: I finally figured it out. After moving all the html from index.html to app.component.ts, everything started working perfectly. The method described below is the correct one. I've been facing an issue where I have a ParentComponent that retrie ...

Angular modal not progressing past initial message due to Bootstrap integration issue

The modal functionality only seems to be working for the first message I send, as subsequent messages do not appear. My environment includes: Angular 17 Bootstrap 5.3 This is the TypeScript file snippet: import { Component } from '@angular/core&apos ...

Exploring the HttpClient inheritance feature in Angular 6

I have customized the httpClient in an Angular project to include a special parameter in the options. This modification is working perfectly in my application. Here is the structure of my new service: export class CustomHttpClient extends HttpClient ...

Ways to eliminate Typescript assert during the execution of npm run build?

How can I effectively remove Typescript asserts to ensure that a production build generated through the use of npm run build is free of assertions? Your assistance is appreciated ...

The function Func<T extends IComponent>( ) returns an array of type T that extends IComponent, which ultimately results in an array of IComponent[] without explicitly assigning

Currently, I am attempting to implement the ECS pattern in TypeScript. I have created a class called ComponentStore that contains components of entities for future handling purposes. Here is an example of what these components look like: class Health impl ...

Unable to iterate through elements when utilizing an external library: Incompatible types, 'Element[]' cannot be assigned to type 'string'

I've encountered an issue while trying to use the react-responsive carousel. It seems to work fine when I manually add my images, but when I try to add them through photos.map, it throws an error: Type 'Element[]' is not assignable to type ...

Transform a collection of interfaces consisting of key-value pairs into a unified mapped type

I have a set of interfaces that describe key-value pairs: interface Foo { key: "fooKeyType", value: "fooValueType", } interface Bar { key: "barKeyType", value: "barValueType", } interface Baz { key: "bazKeyType", value: "bazValue ...

What is causing the "unable to resolve dependency tree" error when using ng new newApp?

Struggling with creating a new Angular app using the command ng new app-name? When running the command, you may encounter the following error in the command line. Installing packages (npm)...npm ERR! code ERESOLVE npm ERR! ERESOLVE unable to resolve depen ...

Tips for aligning the text horizontally in an input field with a neighboring element

Hello amazing community, I'm searching for a neat way to align the text of an element horizontally with that of an Angular Material input field. Here is the code I am using: <div style="display: flex"> <div>Greeting: </div> ...