Angular Validation Error为"ngClass",因为它不是"div"的已知属性. ( [英] Angular Validation Error as 'ngClass' since it isn't a known property of 'div'. (

查看:34
本文介绍了Angular Validation Error为"ngClass",因为它不是"div"的已知属性. (的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在这里,当我尝试2 Load Html页面时,我为EName验证写了一个小的Validation属性,由于它不是'div'的已知属性,因此我收到了'ngClass'的错误消息. (

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>

推荐答案

如果您已经拥有CommonModule/BrowserModule,但仍无法正常工作,请确保您正确键入了属性.我有ngclass而不是ngClass(注意'C').

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').

这篇关于Angular Validation Error为"ngClass",因为它不是"div"的已知属性. (的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆