Angle validation error as ngClass as it is not a known div property. (

Here I wrote a small Validation property to authenticate when I try to load a 2 page Html page. I am getting Error as "ngClass" as it is not a known property of "div". (

Component.ts

import { Component, OnInit } from "@angular/core"
import { Employee } from "../../../templates/employee/employee"
import { Validators, FormGroup, FormBuilder } from "@angular/forms"
@Component({
    selector: "customer-ui",
    templateUrl: "../../../templates/customer/customer.html"
})
export class JamComponent implements OnInit {
    EmpleoyeeForm: FormGroup;
    public constructor(private fb: FormBuilder) {}
    ngOnInit(): void {
        this.EmpleoyeeForm = this.fb.group({
            EmpName: ['', [Validators.required]]

        })
    }

      

Htmlcode

<form class="form-horizontal" novalidate [formGroup]="EmpleoyeeForm">

    <fieldset>
        <div class="form-group" [ngClass]="{'has-error': (EmpleoyeeForm.get('EmpName').touched ||
                                                  EmpleoyeeForm.get('EmpName').dirty) &&
                                                    !EmpleoyeeForm.get('EmpName').valid }">

            <label for="name">Name</label>
            <input type="text" class="form-control" formControlName="EmpName" [(ngModel)]="EmpName" />

        </div>
    </fieldset>
</form>

      

+8


source to share


4 answers


You need to add BrowserModule

@NgModule(
  imports: [BrowserModule, /* other imports */],
  ...
)

      



If CommonModule is imported in child module.

import { CommonModule } from "@angular/common"

      

+38


source


If you already have a CommonModule / BrowserModule and it still doesn't work, also make sure you entered the attribute correctly. I had ngclass

instead ngClass

(note the 'C').



+2


source


import {CommonModule} from '@ angular / common';

...

import: [CommonModule],

0


source


Thanks, I faced the same problem when using multiple modules. Problem fixed

-1


source







All Articles