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

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

问题描述

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

Component.ts

import { Component, OnInit } from "@angular/core"从../../../templates/employee/employee"导入{员工}从@angular/forms"导入 { Validators, FormGroup, FormBuilder }@成分({选择器:客户用户界面",templateUrl: "../../../templates/customer/customer.html"})导出类 JamComponent 实现 OnInit {员工表格:表格组;公共构造函数(私有 fb:FormBuilder){}ngOnInit(): 无效 {this.EmpleoyeeForm = this.fb.group({EmpName: ['', [Validators.required]]})}

HTML 代码

<字段集><div class="form-group" [ngClass]="{'has-error': (EmpeoyeeForm.get('EmpName').touched ||EmpleoyeeForm.get('EmpName').dirty) &&!EmpeoyeeForm.get('EmpName').valid }"><label for="name">Name</label><input type="text" class="form-control" formControlName="EmpName" [(ngModel)]="EmpName"/>

</fieldset></表单>

解决方案

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

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>

解决方案

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

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

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