The element property cannot be found on the specified Element type in ANGULAR

Unable to resolve error in ng build --prod after successful execution of ng serve: Error - Property 'element' does not exist on type 'Element'.

https://i.sstatic.net/l3KX4.png

Edit-depart.html

  
  <form #employeeForm="ngForm" (ngSubmit)="onSubmit(employeeForm)" novalidate>
      <input  type="hidden" name="id" [(ngModel)]="data.element.id" />
    <h2 mat-dialog-title>Modifier Courrier Depart</h2>
    <mat-dialog-content class="mat-typography">
      <mat-card>
        <mat-card-header fxLayoutAlign="center">                
          <mat-card-subtitle><h2>Information</h2></mat-card-subtitle>
      </mat-card-header>
      <table cellspacing="2" class="w-100">
        <tr>
            <td>
                <mat-form-field class="w-100" appearance="outline" >
                  <mat-select placeholder="Type Contrat" name="type" [(ngModel)]="data.element.type">
                    <mat-option *ngFor="let contrat of contrats" [value]="contrat.value" >
                       {{contrat.viewValue}}
                    </mat-option>
                </mat-select>
                </mat-form-field>
            </td>
            <td>
              <mat-form-field class="w-100" appearance="outline">
                <input matInput placeholder="Destinataire" name="destinataire" [(ngModel)]="data.element.destinataire">
             
              </mat-form-field>
            </td>
        </tr>
    </table>
    </mat-dialog-content>
    <mat-dialog-actions align="end">
        <button mat-raised-button color="primary" type="submit" [disabled]="!employeeForm.valid" [mat-dialog-close]>Update</button>
    </mat-dialog-actions>
    </form>

departs.component.ts

editDepart(element: Element) {
   // this.selectedEmployee = element;
   
    let dialogRef = this.dialog.open(EditDepart,  { disableClose: true,data: { element } }); 
    
    dialogRef.afterClosed().subscribe(result => {
      this.refreshEmployeeList();
    })    
    
   }
export interface Element {
  id: any;
  type: any;
  destinataire: any;
}

Edit-depart

  export class EditDepart {

     constructor( private _employeeService: EmployeeService,

public dialogRef: MatDialogRef, @Inject(MAT_DIALOG_DATA) public data: Element) {

     }
    
    @Output() submit: EventEmitter<any> = new EventEmitter();
    
     onSubmit(form: NgForm) {
      if (form.value.id == null) {
        this._employeeService.postEmployee(form.value).subscribe((res) => {
          
          this._employeeService.getEmployeeList().subscribe((res) => {
           
              this.submit.next(res as Employee[]);
           
          });
        //  M.toast({ html: "Saved successfully.", classes: "rounded" });
        });
      }
      else {
    
        this._employeeService.putEmployee(form.value).subscribe((res) => {
          
          this._employeeService.getEmployeeList().subscribe((res) => {
              this.submit.next(res as Employee[]);
              //this.employees = employees;
           
          });
          
        });
      }
    }
      
     
    }

Answer №1

When working in the edit department component, you have defined

public dialogRef: MatDialogRef, @Inject(MAT_DIALOG_DATA) public data: Element) {

This expects data to be of type Element when in reality data is of type {element: Element}

You can either change it to

@Inject(MAT_DIALOG_DATA) public data: any

or adjust the value assigned to data like this:

let dialogRef = this.dialog.open(EditDepart,  { disableClose: true,data: { ...element } });

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

The requestAnimationFrame function is only being executed a single time

I'm facing a challenge with creating a simple animation using ThreeJS in my Ionic 2 project. The goal is to rotate a cube, but unfortunately, the cube remains static as the requestAnimationFrame function is only triggered once inside the render loop. ...

How can pipes be utilized on parameters for translation in Angular?

When faced with the task of displaying multiple texts for translation, each containing different parameters like dates, numbers, and currencies, is there a way to effectively nest angular pipes? While I am aware that I can create a proxy object in the com ...

What are some effective strategies for creating customizable and dynamic filtering and sorting features in Angular (^11) that can be reused across different components?

I am looking to integrate custom ordering and filtering capabilities into my application in a way that is easily reusable across various components. These functions will be essential for enabling users to sort list/table contents and filter arrays within t ...

Issue with nestjs build due to ts-loader module in dev-dependency

I've encountered a Module Error with ts-loader during a docker build ERROR [6/6] RUN nest build 3.9s ------ > [6/6] RUN ...

What is the best way to output the leaf nodes from an array of object lists in TypeScript?

Having trouble with TypeScript, specifically working with arrays and filtering out leaf nodes. I want to print only the leaf nodes in the array, resulting in ['002', '004', '007']. Can someone please assist me? Excited to lear ...

Encountering difficulties when compiling my Angular application

Currently, I am working with Angular 2. To include Bootstrap in my project, I utilized the node.js command prompt for installation. npm install ngx-bootstrap --save I made adjustments to the .csproj file in order to deploy my application on the server vi ...

Exploring the integration of React.Components with apollo-client and TypeScript

I am in the process of creating a basic React component using apollo-client alongside TypeScript. This particular component is responsible for fetching a list of articles and displaying them. Here's the code: import * as React from 'react' ...

Switch up the default font in your Nuxt 3 and Vuetify 3 project

I've been doing a lot of searching on Google, but I can't seem to find the solution. It seems like the challenge might be that the Nuxt 3 + Vuetify 3 combination isn't widely used yet? My current task is to implement a custom default font. ...

Show the outcome stored within the const statement in TypeScript

I am trying to display the outcome of this.contract.mint(amount, {value: this.state.tokenPrice.mul(amount)}) after awaiting it. I want to see the result. async mintTokens(amount: number): Promise<void> { try { let showRes = await this.c ...

Issue observed: The app.module.ts file is missing from the src/app folder in the Angular project

While attempting to create a new Angular project, I've noticed that my app.module is not being generated. Despite updating my node version and npm, as well as examining anything else that might be causing the issue, the app.module still isn't app ...

Determine the data type of a parameter by referencing a prior parameter

Consider a scenario in my software where I have two distinct implementations of an Event Emitter. For instance: type HandlerA = (data: boolean) => void; type HandlerB = (data: number) => void; // HandlerB is somehow different from HandlerA type Eve ...

There was an issue encountered while trying to execute npm install, resulting in the error message: "This is a glitch

I am diving into the world of Angular and Node for the first time. I'm currently attempting to run a project that combines Angular with Neo4j, but encountering some issues along the way. When I initially tried to launch the project as is, after openin ...

When a child triggers a non-bubbling event, the view reference in Angular 2 structural directive is automatically cleared

Imagine we have a set of images that need to be displayed: <div *ngFor="let image of images; let i = index"> <div *appMaskImageOnError="i" #mydir> <img [src]="image" alt="" (error)="mydir.remove()"> </div> < ...

Tips for changing a value in an ngIf template

Hi there, I'm fairly new to Angular and I am trying to make some changes in the ngIf template. I have created a component called research-list and I want to display the research data defined in research-list.ts file. However, when I try to use modify( ...

Typescript not flagging an error for an object being declared without a type

I am encountering an issue with my tsconfig.json file: { "compilerOptions": { "allowJs": true, "allowSyntheticDefaultImports": true, "baseUrl": "src", "isolatedModules": true, "jsx": "preserve", "esModuleInterop": true, "forc ...

Issue encountered when trying to bring in a component from a different module

I am attempting to import the 'OpenDialogContentComponent' component from Module A into Module B, however I am encountering this error: 'Cannot determine the module for class OpenDialogContentComponent in C:/Users/jitdagar/Desktop/TDP/pwt-u ...

When attempting to dispatch an action with switchMap, it fails, while map successfully triggers the

I recently started utilizing ngrx and ngrx/effects. In the code snippet below, I encountered an issue where using switchMap with concatLatestFrom and dispatching an action fails, while using map seems to work perfectly fine. Any idea why? When trying to ...

Is there a way to create a tuple property that can be called like a

I have a specific function in my code: function test(cb: Function | number) { let item = { height: 0} if(typeof cb === 'number') { item.height = cb; } if(typeof cb === 'object') { item.height = cb(); } } This function ...

Encountering an error message that reads "State.Push is not a valid function" upon integrating

Currently, I am working on developing a Todo app using react-typescript and redux. During testing, I noticed that the app functions properly without redux-persist, displaying the list of added tasks. However, upon integrating redux-persist, the store does ...

Angular 6: How to Retrieve the Child Component nested within another Child Component from the Parent Component

Is there a way to access and call specific methods of child components within a parent component? For example, if we have a ParentCmp containing two child components (with their selectors and template refs), how can we call certain methods of LoadingPanels ...