Angular Validation Error as 'ngClass' since it isn't a known property of 'div'. (

自闭症网瘾萝莉.ら 提交于 2019-12-12 09:34:36

问题


Here i wrote a small Validation Property for EName Validation when i try 2 Load Html page i'm getting Error as 'ngClass' since it isn't 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>

回答1:


You need to add BrowserModule

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

If it is in a child module import CommonModule.

import { CommonModule } from "@angular/common"



回答2:


If you already have the CommonModule/BrowserModule and it's still not working, also make sure you typed the attribute correctly. I had ngclass instead of ngClass (notice the 'C').




回答3:


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

...

imports: [CommonModule],



来源:https://stackoverflow.com/questions/44870542/angular-validation-error-as-ngclass-since-it-isnt-a-known-property-of-div

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!