The component does not recognize the property 'endDate' and is unable to access it

The property endDate is not found on the type TestComponent

test.Component.cs

--

import { Component} from '@angular/core';
import { Router } from '@angular/router'
import {Message} from 'primeng/api';
import { FormGroup, FormControl, FormBuilder, Validators } from '@angular/forms';

@Component({
  templateUrl: './test.component.html',
  selector: 'test',
  providers:[TestService]
})
export class TestComponent  {
    public testingForm: FormGroup;

    constructor(
        private router: Router,
        private userService: UserService,
        ,private formBuilder: FormBuilder
      ) { 
        console.log("Inside constructor...");
      }
      
      ngOnInit():void {  
           console.log("Inside onNotify ...."); 
           this.testingForm = this.formBuilder.group({
            startDate: new FormControl('', Validators.required), 
            endDate: new FormControl('', Validators.required), 
            message: new FormControl('', Validators.required)
           });     
           this.loadData();       
      }
      
      ...////.....
      
      
      }

--

test.component.html

--

<form [formGroup]="testingForm"  >
<div>
<label class="control-label col-sm-4">Start Date:</label>
<div class="col-sm-8">
    <p-calendar formControlName="endDate" [showIcon]="true"></p-calendar><span style="margin-left:35px">{{endDate|date}}</span>
</div>
</div>
</form>

app.module.ts - includes the import for FormsModule and ReactiveFormsModule

import { FormsModule, ReactiveFormsModule } from '@angular/forms';

The error encountered:

 ERROR in src/testing/test.component.html:37:115 - error TS2339: Property 'endDate' does not exist on type 'testingComponent'.

    37             <p-calendar formControlName="endDate" [showIcon]="true"></p-calendar><span style="margin-left:35px">{{endDate|date}}</span>
                                                                                                                         ~~~~~~~

      src/testing/test.component.ts:19:16
        19   templateUrl: './test.component.html',
                          ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
        Error occurs in the template of component TestComponent.

Your feedback is greatly valued. Thank you in advance.

Answer №1

Indeed, it is accurate that it does not.

To retrieve it from the FormGroup, you can incorporate a getter function like this:

get selectedDate(): Date {
    return this.dynamicForm ? this.dynamicForm.value.selectedDate : null;
}

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 it feasible to update the value of a FormArray within a FormGroup?

Hey there, I'm new to working with reactive forms and I have a question about updating a FormArray without using the get method. Typically, I would use something like this.editForm.get('ingredients'). However, I would like to use patchValue ...

It seems that in order to use Angular 2 with Firebase Hosting, the hash marking is

Is it possible to set up normal URLs for routes in Angular 2 with Firebase Hosting? An example route would be: I attempted to deploy my website on Firebase hosting with routes structured this way, but I faced issues navigating to the routes. To resolve ...

Working with Angular2: Linking dropdown values with any number of items

Is there a way to dynamically bind drop down values with numbers from 1 to 100 using a loop in Angular2? I am currently using Ngprime dropdown for a limited number of values, but how can I achieve this for any number of values? Here is the template: < ...

Encountered an issue when trying to convert JSON into an array and loop through it in an HTML file using a

Currently, I am working on a project involving Angular where I am retrieving data from an API through a GET call. Specifically, one column's data is being converted from JSON to an array. However, when attempting to iterate over this array in the HTML ...

Typescript PDFjs encountering loading issues with corrupt files

In my Vue.js application, I have the following TypeScript class: /** Taken from https://github.com/VadimDez/ng2-pdf-viewer/blob/master/src/app/pdf-viewer/pdf-viewer.component.ts */ import { Component, Vue } from 'vue-property-decorator'; import ...

Setting the default value for Angular Material's select component (mat-select)

Many inquiries are focused on setting a default value to display in a "Select" control. In this particular case regarding Angular 8 template driven forms, the issue lies in the inability to show the default value in the mat-select when the button is clicke ...

Tips for fixing: "Object may be null" error in Angular routing

Currently, I am working on the angular heroes tutorial provided in the angular documentation and encountering an error. An issue has been detected, which states that the object is possibly 'null'. getHero(): void { const id = +this.route.snaps ...

Unable to activate parameter function until receiving "yes" confirmation from a confirmation service utilizing a Subject observable

Currently, I am working on unit tests for an Angular application using Jasmine and Karma. One of the unit tests involves opening a modal and removing an item from a tree node. Everything goes smoothly until the removeItem() function is called. This functi ...

Reduce the value of the variable within a different component within an angular framework

I am working with 2 different components: Left Component Main Component Left Component The left component contains a button that can only be clicked 5 times. Once it has been clicked 5 times, the button becomes disabled. <button class="btn gbtn ...

Having trouble with obtaining precise mouseup and mousedown coordinates

Currently, I am working with react and typescript for my project. I have implemented a canvas element where I am attempting to draw a rectangle based on mouseup and mousedown events. However, the issue I am facing is that the rectangles are being drawn in ...

The error message "Property 'name' does not exist on type 'User'" is encountered

When running this code, I expected my form to display in the browser. However, I encountered an error: Error: src/app/addproducts/addproducts.component.html:18:48 - error TS2339: Property 'price' does not exist on type 'ADDPRODUCTSComponent& ...

Angular: How to restrict the compilation of rgba() to #rrggbbaa in your codebase

There are some browsers that do not support #rrggbbaa but do support rgba(). However, in my Angular project, background-color: rgba(58, 58, 58, 0.9) in common.css was compiled to background-color:#3a3a3ae6 in style.[hash].css. How can I prevent this co ...

Create the Angular 6 service within the directory "e2e/app"

After upgrading my Angular 4 to 6, I attempted the following command: ng generate service security/security However, the service was generated under the "e2e/app" folder instead of the expected "src/app" location. Below is an excerpt from my angular.json ...

exit out of React Dialog using a button

I have a scenario where I want to automatically open a dialog when the screen is visited, so I set the default state to true. To close the dialog, I created a custom button that, when clicked, should change the state to false. However, the dialog does no ...

Is it possible to leverage Kafka consumer/producer in Angular 9 for interacting with a Node server?

I'm working on connecting Kafka from the client-side with Angular-9 through a node.js server. I've successfully implemented this code on the Node server and now I want to achieve the same functionality in Angular9. https://i.sstatic.net/1yJRg.pn ...

Having some issues with formatting a date using an angular pipe, it seems to not be functioning correctly

I'm facing an issue with the date formatting using the date pipe in Angular 7. When I try to format it as date : 'dd/MM/yyyy', nothing changes. The date still appears like this: Mon Oct 12 1992 00:00:00 GMT-0500 (Central Daylight Time) I ...

Troubleshooting Socket.io with TypeScript: Issues with Socket.io recognizing new connections

Attempting to integrate socket.io with my basic express application using typescript. Here's my current setup: server.ts import express from "express"; import { Server, Socket } from "socket.io"; import { createServer, Server as S ...

Troubleshooting image upload issues with AWS S3 in Next.js version 13

I encountered a consistent problem with using the AWS SDK in NextJS to upload images. I keep getting error code 403 (Forbidden). Could there be other reasons why this error is occurring besides the accessKeyId and secretAccessKey being invalid? Below is my ...

Order an array based on a specified list of fields

Imagine you have an array of objects: People = [ { "id": 1, "name": Joseph, function: "preacher"}, { "id": 2, "name": Ann, function: "singer"}, { "id": 3, "name": Miles, functi ...

Unspecified parameter for Next.js dynamic route

Currently, I am developing an e-commerce application using next.js with Typescript and MongoDB. To better understand my project, let's take a look at my existing file structure: https://i.stack.imgur.com/tZqVm.png The mainPage.tsx file is responsibl ...