angularjs 无法绑定到'ngmodel',因为它不是'input'的已知属性,窗体模块已存在

7dl7o3gd  于 2023-06-04  发布在  Angular
关注(0)|答案(2)|浏览(402)

我还在app.module.ts文件中包含了表单模块部分。错误仍然存在。不知道Error occurs in the template of component UpdateEmployeeComponent.是什么意思。
我做了拼写检查。我删除了整个代码并重新编写。因为我已经包含了表单模块部分,我不知道该怎么做。
下面给出的是我的update-employee.component.html代码。

type here<!DOCTYPE html>
<html>
<div class="row">
    <div class="card col-md-6 offset-md-3 offset-md-3">
        <div class="row">
            <h3 class="text-center"> Update Employee </h3>
            <hr />
            <div class="card-body">
                <form (ngsubmit)="onSubmit()">

                    <div class="form-group">
                        <label> First Name</label>
                        <input type="text" class="form-control" id="firstName" [(ngmodel)]= "employee.firstName"
                            name="firstName">
                    </div>

                    <div class="form-group">
                        <label> Last Name</label>
                        <input type="text" class="form-control" id="lastName" [(ngmodel)]="employee.lastName"
                            name="lastName">
                    </div>

                    <div class="form-group">
                        <label> Email Id</label>
                        <input type="text" class="form-control" id="emailId" [(ngmodel)]="employee.emailId"
                            name="emailId">
                    </div>
                    <br />
                    <button class="btn btn-success" type="submit">Submit</button>

                </form>
            </div>
        </div>
    </div>
</div>
</html>
Can't bind to 'ngmodel' since it isn't a known property of 'input'.ngtsc(-998002)
update-employee.component.ts(9, 32): Error occurs in the template of component UpdateEmployeeComponent.

这就是我得到的错误。
这是app.module.ts文件代码。

import { BrowserModule } from '@angular/platform-browser';
import { NgModule } from '@angular/core';
import { HttpClientModule } from '@angular/common/http'
import { AppRoutingModule } from './app-routing.module';
import { AppComponent } from './app.component';
import { EmployeeListComponent } from './employee-list/employee-list.component';
import { CreateEmployeeComponent } from './create-employee/create-employee.component';
import { FormsModule} from '@angular/forms';
import { UpdateEmployeeComponent } from './update-employee/update-employee.component';
import { EmployeeDetailsComponent } from './employee-details/employee-details.component'
import {RouterModule} from '@angular/router';
import { ReactiveFormsModule } from '@angular/forms';
import { CUSTOM_ELEMENTS_SCHEMA } from '@angular/core';

@NgModule({
  imports: [RouterModule],
 
})

@NgModule({
  declarations: [
    AppComponent,
    EmployeeListComponent,
    CreateEmployeeComponent,
    UpdateEmployeeComponent,
    EmployeeDetailsComponent
  ],
  imports: [
    BrowserModule,
    AppRoutingModule,
    HttpClientModule,
    FormsModule,
    ReactiveFormsModule,

  ],
  schemas: [
    CUSTOM_ELEMENTS_SCHEMA
  ],
  providers: [],
  bootstrap: [AppComponent]
})
export class AppModule { }
xzv2uavs

xzv2uavs1#

在ts中employees.firstname应该有初始值

jm2pwxwz

jm2pwxwz2#

我找到了答案。这是我加的一组额外的括号。

相关问题