Displaying Information in Angular Modal Windows

I'm facing an issue while trying to create an edit button for a formGroup that is initially saved. When the user clicks on the adjacent button, a modal should open with editable data. However, I encountered this error and haven't been able to resolve it yet. I would appreciate any help from the community.

ERROR Message: Unable to access property 'startDate' of undefined

Note: The code snippet may not be executable here, but it was the most convenient way to share my code.

import { Component, OnInit } from '@angular/core';
import {FormBuilder, FormGroup} from "@angular/forms";

@Component({
  selector: 'app-project-information-detail-edit',
  templateUrl: './project-information-detail-edit.component.html',

})
export class ProjectInformationDetailEditComponent implements OnInit {

    detailForm : FormGroup;
    constructor(private fb: FormBuilder) { }

    ngOnInit() {
        this.detailForm = this.fb.group({
            name: [''],
            phone: [''],
            startDate: [''],
            email: [''],

        });

    }

}
<form [formGroup]="detailForm">
  <div class="col-sm-6">
    <h1><span class="semi-bold">{{selectedProject.name}}</span>

      <br>
      <small *ngIf="selectedProject.startDate">
        {{selectedProject.startDate}}
      </small>
      <ng-template #noStartdate>
        <span>Not set</span>
      </ng-template>
    </h1>
    <ul class="list-unstyled">
      <li>
        <p class="text-muted">
          <i class="fa fa-phone"></i>&#xA0;&#xA0;
          <span *ngIf="selectedProject.phone">
                    <a href="tel:{{selectedProject.phone}}">{{selectedProject.phone}}</a>
                                                                </span>
          <ng-template #noPhoneTemplate>
            <span>Not available</span>
          </ng-template>
        </p>
      </li>


      <li>
        <p class="text-muted">
          <i class="fa fa-envelope"></i>&#xA0;&#xA0;
          <a *ngIf="selectedProject.email"
             href="mailto:{{selectedProject.email}}">{{selectedProject.email}}</a>
          <ng-template #noPhoneTemplate>
            <span>Not available</span>
          </ng-template>
        </p>
      </li>
    </ul>
  </div>
</form>

ERROR TypeError: Cannot read property 'startDate' of undefined
at Object.eval [as updateDirectives] (ProjectInformationDetailEditComponent.html:9)
at Object.debugUpdateDirectives [as updateDirectives] (core.js:14655)
at checkAndUpdateView (core.js:13802)
at callViewAction (core.js:14153)
at execComponentViewsAction (core.js:14085)
at checkAndUpdateView (core.js:13808)
at callWithDebugContext (core.js:15056)
at Object.debugCheckAndUpdateView [as checkAndUpdateView] (core.js:14593)
at ViewRef_.detectChanges (core.js:11577)
at eval (core.js:5907)

enter code here

Answer №1

You may have overlooked defining selectedProject in your code snippet, as the absence of it would have caused an error with name.

Modify this line

 <small *ngIf="selectedProject.startDate">

to

 <small *ngIf="selectedProject?.startDate"> 

or

 <small *ngIf="selectedProject && selectedProject.startDate"> 

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

Resolving NestJS Custom Startup Dependencies

In my setup, I have a factory responsible for resolving redis connections: import {RedisClient} from "redis"; export const RedisProvider = { provide: 'RedisToken', useFactory: async () => { return new Promise((resolve, reject ...

Angular is unable to locate images within the assets directory if they are nested within a subfolder

Despite my efforts to set a default PNG image for users who do not upload their own, I have been unable to get it to display after an hour of troubleshooting. <img src="assets/images/image-card.png" /> I attempted to modify the asset value ...

Generate an interactive sitemap.xml in ReactJS for each request made to http://example.com/sitemap.xml

I am working on a single-page application (SPA) using reactjs, and I have links in the format of http://example.com/blog/:id. I want to dynamically generate a sitemap for this site. While I'm aware that there are npm packages like react-router-sitema ...

Is the latest Swiper JS version compatible with outdated web browsers?

Seeking information on browser compatibility. I am interested in upgrading to the latest version 8.4.5 of Swiper JS for my project, currently using version 4.1.6. Upon examining their shared Github repository file .browserslistrc, I noticed changes that ta ...

What steps are involved in developing an Angular library wrapper for a pre-existing Javascript library?

Imagine having a vanilla Javascript library that is commonly used on websites without any frameworks. How can you create an Angular library that can be easily installed via npm to seamlessly integrate the library into an Angular application? The process o ...

Mastering Interpolation in React with TypeScript is essential for creating dynamic and interactive UI components. By leveraging the

Incorporating and distributing CSS objects through ChakraUI presents a simple need. Given that everything is inline, it seems the main issue revolves around "& > div". However, one of the TypeScript (TS) errors highlights an unexpected flagging of ...

What is the correct approach for detecting object collisions in Phaser 3?

Hey everyone, I'm facing a problem and could use some assistance. Currently, I am trying to detect when two containers collide in my project. However, the issue is that the collision is being detected before the objects even start moving on screen. It ...

Struggling to transfer array data from service to component

I am currently working on passing an array from service.ts to a component. My goal is to display the array elements in a dialog box. However, I encountered a Typescript error TypeError: Cannot read property 'departmentArr' of undefined. I am str ...

Unable to Navigate with NativeScript

Having recently ventured into Angular and NativeScript, I am currently working on creating an app. While I have successfully built my first page, I am facing some challenges with routing to my signInComponent. This is the setup that I currently have: In a ...

Removing HTML Tags in Ionic - A How-To Guide

After utilizing Ionic 3 to retrieve data from a WordPress API, I am encountering an issue with displaying the content on the app UI. The problem arises from the presence of HTML tags within the content being printed along with the text. While seeking solut ...

Utilizing TypeScript's conditional types in conjunction with enums

In my code, there is a TypeScript enum defined like this: enum UIConfigurationType { DisplayTableFields = "display-table-field", FormFields = "form-field", MainAttributes = "main-attribute", SearchAttributes = "se ...

Changing the default route in Angular 2 based on conditions

I'm currently developing an application where, upon entering the page, the default route for the user is the "Login" page. However, I want to implement a condition based on whether the user has a local storage variable (id) set. If this variable exist ...

Unable to test the subscribe functionality in Angular

There is a subscribe method in my ts file within ngAfterViewInit() that is not triggering as expected during testing and debugging. I need to manually set mock data inside the subscribe method for testing purposes. ts file import mockData from 'test ...

A step-by-step guide on accessing and displaying local Storage JSON data in the index.html file of an Angular project, showcasing it on the

I am facing an issue with reading JSON data from localStorage in my Angular index.html file and displaying it when viewing the page source. Below is the code I have attempted: Please note that when checking the View page source, only plain HTML is being ...

Steps for connecting data to a react table

This is my first time working with React and I want to display the following data (id, name, status, and quantity): interface Goods { id: number; name: string; status: string; quantity?: number; } export const getGoods = (): Promise<Goods[]> ...

a user-friendly database solution for storing data in HTML 5 and Google Drive

Greetings, I am currently faced with the following dilemma: As I work on my angular 2 application, I find myself needing to save certain data. Personally, I have a preference for saving data in JSON format. Here is the scenario: Imagine a todo list where ...

The default route in Angular2 RC5 is set to display the AppComponent

My Angular2 application starts with an AppComponent that contains the main navigation bar and router outlet for the rest of the app. By convention, this is considered the starting point of the application. I also have a routes component that currently doe ...

Utilizing absolute path in Typescript: A comprehensive guide

I am currently working on a project written in Typescript running on NodeJS. Within the project, I have been using relative paths to import modules, but as the project grows, this approach is becoming messy. Therefore, I am looking to convert these relativ ...

Issues with TypeScript bundling external modules

I have a sample TypeScript code that I am attempting to bundle multiple ts/tsx files using the typescript compiler (tsc). Below is the code: File: ISample.ts class ISample{ constructor(public value:string){ } } export = ISamp ...

Resolving CORS Error in Angular and PHP: A Comprehensive Guide

My current project involves learning Angular and creating a solution that communicates with an IIS Server running on PHP as an API. The IIS server is set up with Windows Authentication to authenticate users, and the combination of IIS/PHP is functioning p ...