Angular 13/14 – property ‘name’ comes from an index signature, so it must be accessed with [‘required’]

[ad_1]

Angular 13/14 – property ‘name’ comes from an index signature, so it must be accessed with [‘required’]; In this tutorial, we will learn how to remove property ‘name’ comes from an index signature, so it must be accessed with [‘required’] error in angular 13/14 apps.

Let, you have a form and your angular 13/14 apps and you validate your form data like following:

<div class="form-group">

    <label for="name">Name</label>

    <input 

        formControlName="name"

        id="name" 

        type="text" 

        class="form-control">

    <div *ngIf="f.name.touched && f.name.invalid" class="alert alert-danger">

        <div *ngIf="f.name.errors && f.name.errors.required">Name is required.</div>

        <div *ngIf="f.name.errors && f.name.errors.minlength">Name should be 3 character.</div>

    </div>

</div>

At that time, this error will occur property ‘name’ comes from an index signature, so it must be accessed with [‘required’]:

We can use the following code to remove or solve this error:

<div class="form-group">
    <label for="name">Name</label>
    <input 
        formControlName="name"
        id="name" 
        type="text" 
        class="form-control">
    <div *ngIf="f['name'].touched && f['name'].invalid" class="alert alert-danger">
        <div *ngIf="f['name'].errors && f['name'].errors['required']">Name is required.</div>
        <div *ngIf="f['name'].errors && f['name'].errors['minlength']">Name should be 3 character.</div>
    </div>
</div>

[ad_2]

Jaspreet Singh Ghuman

Jaspreet Singh Ghuman

Jassweb.com/

Passionate Professional Blogger, Freelancer, WordPress Enthusiast, Digital Marketer, Web Developer, Server Operator, Networking Expert. Empowering online presence with diverse skills.

jassweb logo

Jassweb always keeps its services up-to-date with the latest trends in the market, providing its customers all over the world with high-end and easily extensible internet, intranet, and extranet products.

GSTIN is 03EGRPS4248R1ZD.

Contact
Jassweb, Rai Chak, Punjab, India. 143518
Item added to cart.
0 items - 0.00