为什么 ngModel 不适用于 Angular 17 的最新版本?

问题描述 投票:0回答:1

我正在尝试在我的角度应用程序中创建一个表单,但是当我想在我的表单上实现 ngModel 时:

    <form (ngSubmit)="onSignUp()" #signupForm="ngForm">
        <h1>Connexion</h1>
        <input type="email" name="mail" [(ngModel)]="userLogin.email" placeholder="Email" />
        <input type="password" name="mdp" [(ngModel)]="userLogin.password" placeholder="Password" />
        <a href="#">Mot de passe oublie ?</a>
        <button type="submit">Se Connecter</button>
    </form>

我有这个错误:

NG8002:无法绑定到“ngModel”,因为它不是“input”的已知属性。 [插件角度编译器]

我无法在 app.module.ts 中导入 FormsModule,因为 Angular 17 上不存在该文件,我只有一个 app.config.ts 文件。

有人可以解释一下我该怎么做吗?

javascript html angular typescript angular-ngmodel
1个回答
0
投票

如果你的组件设置了

standalone: true
,那么你需要将
FormsModule
添加到组件的
imports
数组中!

@Component({
  ...
 imports: [
      ...
      FormsModule,
      ...
  ],
  ...
})
© www.soinside.com 2019 - 2024. All rights reserved.