The error message "Ionic 3 encountering issues with accessing property 'valid' from undefined or null reference"

As I was setting up a form on a CRUD using Firebase, initially just storing name and number as string types, I decided to add more parameters of the same type. However, I encountered an issue with the error message "Unable to get property 'valid' of undefined or null reference". Despite trying a few fixes, I have not been able to resolve it successfully. Here's an excerpt from my .html file:

Contact-edit.html

<ion-header>
  <ion-navbar color="primary">
    <ion-title>{{ title }}</ion-title>
  </ion-navbar>
</ion-header>

<ion-content padding>
  <form [formGroup]="form">
    <ion-item>
      <ion-label stacked>Unit</ion-label>
      <ion-input type="text" formControlName="unit"></ion-input>
    </ion-item>
    <ion-item *ngIf="!form.controls.unit.valid && (form.controls.unit.dirty || form.controls.unit.touched)" color="danger">
      <div [hidden]="!form.controls.unit.errors.required">
        Field is required
      </div>
    </ion-item>

    <ion-item>
      <ion-label stacked>Address</ion-label>
      <ion-input type="text" formControlName="address"></ion-input>
    </ion-item>
    <ion-item *ngIf="!form.controls.address.valid && (form.controls.address.dirty || form.controls.address.touched)" color="danger">
      <div [hidden]="!form.controls.address.errors.required">
        Field is required
      </div>
    </ion-item>

    // More HTML code...

  </form>
</ion-content>

In case it's helpful, here's the contact-edit.ts file:

import { ContactProvider } from './../../providers/contact/contact';
// Other imports...

@IonicPage()
@Component({
  selector: 'page-contact-edit',
  templateUrl: 'contact-edit.html',
})
export class ContactEditPage {
  // Component code...
}

// Additional errors displayed:
<pre><code>> ERROR TypeError: Cannot read property 'valid' of undefined
    at Object.eval [as updateDirectives] (ContactEditPage.html:33)
    at Object.debugUpdateDirectives [as updateDirectives] (core.js:14697)
    // More error information... 

Answer №1

It seems like there is a missing hour control in the form group you have created.

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

TypeScript introduces a new `prop` method that handles missing keys in objects

Is there a way to create a prop function that can return a default type if the specified key is not found in object o? type Prop = <K, O extends {}>(k: K, o: O) => K extends keyof O ? O[K] : 'Nah'; /* Argument of type 'K ...

What methods can be used to obtain download statistics for an Angular2 npm package?

Currently working on a presentation for an upcoming conference and faced with a bit of confusion... I'm having trouble locating the download statistics for the angular2 npm package! I've been looking here but unfortunately, there doesn't se ...

sending arguments to angular directive

It was causing me some concern to see the number of global Angular change detections triggered every time an event occurs. That's why I stumbled upon Angular 2 runOutsideAngular still change the UI and decided to implement the 'OutSideEventHandle ...

A function in Typescript designed to take in two objects that possess identical keys

I am looking to define a function that takes two parameters, each being an object. These objects have the same keys, but the data types of the values under those keys should be different (yet the same within each object). I attempted to achieve this using ...

Router navigation does not trigger LifeCycle calls

I currently have the following routes set up: {path:'home', component:HomeComponent, canActivate: [AuthGuard]}, {path:'profile', component:UserProfileComponent, canActivate: [AuthGuard] }, Additionally, in my navbar.component, I hav ...

The React component using createPortal and having its state managed by its parent will remain static and not refresh upon state modifications

I am facing a problem that can be seen in this live example: https://stackblitz.com/edit/stackblitz-starters-qcvjsz?file=src%2FApp.tsx The issue arises when I pass a list of options to a radio button list, along with the state and setter to a child compon ...

Error alert: TypeScript typings issue - Naming conflict with Promise / Failure to locate name Promise

I am currently working on a client/server JavaScript application and I am facing a significant issue with Promises. It appears that they are either undefined or duplicated, and this problem seems to be related to the @types package. npm install --save @ty ...

Apply a dynamic function to assign a background color to a specific class

Currently, I have a function called getBackground(items) that returns a background color from a JSON file list. Within my application, there is a component that automatically adds a class name (.item-radio-checked) when a user clicks on an item in the list ...

Is the indigo-pink color scheme fully implemented after installing @angular/material and scss using ng add command?

After running ng add @angular/material, we are prompted to choose a CSS framework and theme. I opted for indigo-pink and scss. Will the material components automatically inherit this theme, or do we need to take additional steps? When using normal CSS (wi ...

Error: Name 'AudioDecoder' could not be located

In my current project using React and TypeScript with Visual Studio Code 1.69.2 and Node 16.15.1, I encountered an issue. I am attempting to create a new AudioDecoder object, but I keep getting an error message stating "Cannot find name 'AudioDecoder ...

Using jQuery in Jest test with Angular 5: A step-by-step guide

I am facing an issue with my Angular component that utilizes a CalendarService. Upon initialization of the component, I invoke the "calendarService.init()" method. The CalendarService is responsible for configuring a semantic-ui-calendar (which relies on ...

What sets apart `lib.es6.d.ts` from `lib.es2015.d.ts` in TypeScript?

I'm a bit confused about ES6 and ES2015. In TypeScript, there are two type declarations available for them: lib.es6.d.ts and lib.es2015.d.ts. Can someone explain the difference between these two? And which one is recommended to use? ...

Steer clear of utilizing Number() when working with scientific notation

I am attempting to perform the following task Number("0.00000000000122") yields 1.22e-12 However, my goal is to convert that number from a String to a Number. console.log(Number("0.00000000000122")) ...

Is it possible for me to transfer a change to the worldwide namespace from my library?

I am looking to enhance an existing TypeScript type within the global namespace in my library and then expose it for use in other projects. Can this be done? Below is my current code: Promise.ts Promise.prototype.catchExtension = function<T>(this ...

Issue encountered in Angular 16: angular-slickgrid is reporting that property 'detail' is not found on type 'Event'

Currently, I am working on integrating angular-slickgrid v6 with Angular 16. In my code snippet, I am using (onClick)="onCellClicked($event.detail.eventData, $event.detail.args)" to retrieve the selected row. However, I encountered an error message stating ...

The child element is triggering an output event that is in turn activating a method within the parent

I am currently utilizing @Output in the child component to invoke a specific method in the parent component. However, I am encountering an issue where clicking on (click)="viewPromotionDetails('Learn more')" in the child component is al ...

The operation failed because the property 'dasherize' is inaccessible on an undefined object

While attempting to execute the following command: ng generate component <component-name> An error occurred saying: Error: Cannot read property 'dasherize' of undefined Cannot read property 'dasherize' of undefined The confi ...

Create your own Angular control - rate stars - with dynamic input values

<div class="rating"> <div style="display: inline-block" *ngFor="let starred of stars; let i = index" (click)="rate(i + (starred ? (value > i + 1 ? 1 : 0) : 1))"> <ng-container *ngIf="starred; else noStar"><mat-icon class=" ...

What is the process of extending a class in TypeScript?

I have a few services that contain the same code: constructor (private http: Http) { //use XHR object let _build = (<any> http)._backend._browserXHR.build; (<any> http)._backend._browserXHR.build = () => { let _xhr = _ ...

Encountering a Typescript error while trying to implement a custom palette color with the Chip component in Material-UI

I have created a unique theme where I included my own custom colors in the palette. I was expecting the color prop to work with a custom color. I tested it with the Button component and it performed as expected. However, when I attempted the same with the ...