2017-07-02 54 views
1

这里我写的ename验证小验证属性,当我尝试2装载Html页面我收到提示为“ngClass”,因为它不是“DIV”的已知属性。(Angular2 Validation Error as'ngClass',因为它不是'div'的已知属性。 (

组件。 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> 
+0

您是否在@ngModule'imports'列表中导入了'FormsModule'? –

+0

是我重要的形式模块 –

回答

10

您需要添加BrowserModule

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

如果是在子模块中导入CommonModule。

import { CommonModule } from "@angular/common" 
+0

没有使用兄弟已经尝试 – Hussain

+0

尝试按照更新 – Sajeetharan

+0

爱你sajeee bhai – Hussain

相关问题