The fields blush crimson just as my fingers hover over the keyboard, ready

I'm facing an issue where the fields are being validated as soon as I open the page without even typing anything. All the fields appear in red from the beginning, making it difficult for me to input any information.

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

primaryFormGroup = new FormGroup({});
  primaryFirstName = new FormControl('', [Validators.required]);
  
  ngAfterViewInit(): void {

    this.primaryFormGroup.addControl('primaryFirstName', this.primaryFirstName);
    this.formGroupPersonalInfo.addControl('primaryFormGroup', this.primaryFormGroup);
    
  }
Html

<div fxLayout="column" fxLayout.gt-sm="row" fxLayoutGap="10px">
  <mat-form-field fxFlex="25">
    <input matInput name="primaryfirstname" fuse-letters-only-format [formControl]="primaryFirstName" [attr.data-name]="sel_primary_firstname_input" [(ngModel)]="applicationService.application.primaryPersonalInfo.firstName"
      placeholder="First name" maxlength="12" minlength="1" required (change)="personalInfoService.searchForWordTest($event)">
    <mat-hint align="end">{{primaryFirstName.value?.length || 0}} / 12</mat-hint>
    <mat-error *ngIf="primaryFirstName.hasError('required')">
      <div [attr.data-name]="sel_primary_firstname_req_errmsg">First name field is required.</div>
      <div fxLayoutAlign="end start" fxFlex>{{primaryFirstName.value?.length || 0}} / 12</div>
    </mat-error>
  </mat-form-field>
</div>

Answer №1

Make sure to verify whether it has been touched prior to displaying an error message.

<mat-error *ngIf="primaryFirstName.hasError('required') && primaryFirstName.touched">

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

Differentiating AWS API errors in TypeScript: A guide

How can I write different handlers in TypeScript for ThrottlingException and ExecutionLimitExceeded when starting a StepFunction execution? new StepFunction.startExecution({}, (err, data) => { if (err) { // Need to identify ThrottlingExcepti ...

The ngModel in AngularJS 2 fails to update when the Jquery Date Picker date is changed

Having an issue with the Jquery UI datepicker within an angularjs 2 component. The datepicker is displaying the changed date, but it's not updating the underlying ngModel: dateSelected. dateSelected: string = ''; The date picker input fie ...

How can we sort an array of data in Angular 2+ that contains both nested and non-nested properties simultaneously?

I am working with a table that has 6 columns, each containing data from a root array: columns: any[] = [{ sortBy: 'startTime', title: 'Order Date' }, { sortBy: 'btcAmount', title: 'BTC' }, { sortBy: 'btcPri ...

What could be causing the module version discrepancy with the package.json file I created?

Recently, I created a project using create-next-app and decided to downgrade my Next.js version to 12. After that, I proceeded to install some necessary modules using Yarn and specified the versions for TypeScript, React, and others. During this setup, I b ...

Positioning CSS for a Responsive Button

Currently, I am working on making my modal responsive. However, I am encountering an issue with the positioning of the "SAVE" button. The button is not staying in the desired position but instead disappears. Below is the snippet of my HTML and CSS: .dele ...

How can I limit the scope of Bootstrap CSS to a specific Angular component?

Has anyone successfully isolated Bootstrap's css file to just one Angular component? I've encountered issues when including the file globally in styles.css or in .angular-cli.json, as the global styles affect other components that shouldn't ...

An issue arises in Angular 17 where the view does not refresh when using setInterval, accompanied by the NG0500

I am currently working on a countdown timer feature where I want to continuously update the 'seconds' value in real-time, but I'm facing an issue with the UI not reflecting these updates. Whenever I attempt to implement this without utilizi ...

Learn the steps to access various file formats including doc, ppt, xlsx, pdf, jpg, and png using the Ionic native file opener

I am currently working on a Hybrid app using Ionic. My goal is to be able to open various types of files (doc, ppt, xlsx, pdf, jpg, png) from the device's internal or external storage using the Ionic Native File Opener plugin. However, I have only bee ...

Datatables obscures Bootstrap4 dropdown menu

When using Bootstrap4 to create a button with a DropDown menu for each row in a DataTables grid, I encountered an issue. Upon clicking the button, the datatables footer cuts off my menu. I am using Angular5 and Bootstrap4. Here is a screenshot of the prob ...

What is the best way to implement custom sorting for API response data in a mat-table?

I have been experimenting with implementing custom sorting in a mat-table using API response data. Unfortunately, I have not been able to achieve the desired result. Take a look at my Stackblitz Demo https://i.sstatic.net/UzK3p.png I attempted to implem ...

Variations in default export behavior in Webpack when using Typescript versus Javascript

In my React application, I have a page that imports a component from another file. // Code snippet from IconPage.tsx import {AccountBalanceIcon} from './icons'; <AccountBalanceIcon /> // Code snippet from ./icons.ts export { default as A ...

Strange Node.js: I always avoid utilizing `require()`, yet encountered an unexpected error

For more information on this particular issue, please refer to this link It's quite puzzling as I haven't used the require() function in my code, yet I'm receiving an error telling me not to use it. How odd! The problematic code snippet i ...

Is it necessary to alert when there is a collision between a TypeScript type and a constant with the same name in a

     I am encountering an issue with my TypeScript code. Here is a snippet from Project.ts:     import type { SomeType } from '../../types/Project'; // import { SomeType } from '../../types/Project'; tried this too const SomeTyp ...

What steps can I take to prevent receiving the error message "Certain components in XXX are not associated with the entity" in Strapi?

User I am facing an issue with my application's endpoint for adding a like to a post. The endpoint is supposed to receive the user id who liked the post and insert it, along with the number of likes (not crucial at this moment), into a database. To ac ...

How to create an Ion-select element with dynamic options in Ionic 2?

Currently, I am working on an application in Ionic 2 and I am facing a challenge with adding ion-select options dynamically. Below is the snippet of my code: <ion-select [(ngModel)]="classifications" (ngModelChange)="updateSelectedValue($event)"> & ...

Is there a way to create numerous div elements in real-time when a click event occurs?

I've created a web application that requires the user to input a product number. Adjacent to the input field is an arrow icon that the user clicks. Upon clicking, there is validation to ensure that the entered number matches one of the valid product n ...

What is the best type to use for an Angular component?

I attempted to pass a concrete component to a dialog: public openDialog(dialogModel: IDialog, component: any): Observable<boolean> { let dialogRef = this.dialog.open(component, { disableClose: true, panelClass: dialogModel.settings.c ...

Navigating the complexities of generic types in Typescript involves understanding how to work

Having an issue with my React + TypeScript application. I am trying to write a function to filter some data: function matchesFilter(element: T, filter: Filters) { const { name, options } = filter; return options.filter(selected => select ...

Encountering a strange issue while attempting to convert a string to a date format using Angular

I am attempting to format a string into a Date. this.deadLine = new Date(this.deadLine); However, when I check the console, I receive an error message saying "Invalid Date". The output of this.deadLine without any specific format is: "2019-10-21T21:00: ...

Combining PowerShell with Angular for seamless integration

As I work on the frontend of a web application using Angular, my goal is to seamlessly integrate it with an existing 'backend' powered by Powershell. Originally part of a desktop app, I now aim to repurpose the Powershell backend for use in a web ...