Hi
I am getting error - Parse error Missing expected ]
First Name
This is required
Thanks
Hi
I am getting error - Parse error Missing expected ]
First Name
This is required
Thanks
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
Jithu ThomasPosted Jun 5, 2024, 6:36 AM
The error "Object is possibly null" occurs because TypeScript is indicating that
empForm.get('firstName').errorsmight benull. To address this, you can use the optional chaining operator (?.) combined with a nullish coalescing operator (??) to safely handle potentialnullvalues.Updated Html Templete: -
Component TypeScript for Reference:
Ramco RamcoPosted Jun 5, 2024, 6:30 AM
Hi
On word errors it is giving error Object is possibly null
Thanks
Jithu ThomasPosted Jun 5, 2024, 6:26 AM
You can able to use Angular's built-in validation capabilities. here is an implementation
app.module.ts
Create a component that will contain your form.
your-component.component.ts
Create the HTML template for your component to include form validation messages.
your-component.component.html
Note this is a simple example for form validation in Angular using Reactive Forms
Ramco RamcoPosted Jun 5, 2024, 6:16 AM
Hi all
I want validation in Reactive forms
Thanks
Jithu ThomasPosted Jun 5, 2024, 6:05 AM
In Angular templates, you cannot use
@ifbecause@ifis not a valid Angular directive. The correct directive to use for conditional rendering in Angular templates is*ngIf.example implimentation:-
Ramco RamcoPosted Jun 5, 2024, 6:02 AM
Hi
In place of ngIf can't we use @if
Thanks
Jithu ThomasPosted Jun 5, 2024, 5:55 AM
The error you're encountering is due to incorrect syntax in the Angular template. The
*ngIfdirective should be used instead of@if, and the syntax for accessing form control errors is also incorrect.Here’s the corrected version of your template:
Explanation:
*ngIf: Angular templates use*ngIffor conditional rendering.getmethod on the form (empForm.get('firstName')).errors?.['required']to check for specific validation errors.Make sure that your component has the form group and form control defined correctly:
With these changes, your form should work correctly, and the error messages should display appropriately based on the validation state.