蚂蚁 - 可以绑定到' ngmodel'由于它是Nz-Switch的已知属性,因此

发布于 2025-01-31 11:20:27 字数 262 浏览 3 评论 0原文

我正在为Angular(NG-Zorro-Antd)使用ANT设计,并使用Simple Switch模块显示开关。

当我根据文档添加代码时:

< nz-switch [ngmodel] =“ true”></nz-switch>

该应用程序不会编译,我会收到此错误:

无法绑定到“ ngmodel”,因为它不是'nz-switch'的已知属性

I'm using Ant Design for Angular (ng-zorro-antd), and using the simple switch module to display a switch.

When I add the code per the docs:

<nz-switch [ngModel]="true"></nz-switch>

The app won't compile, and I get this error:

Can't bind to 'ngModel' since it isn't a known property of 'nz-switch'

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

娇妻 2025-02-07 11:20:28

import formsModule在右模块中

虽然它在文档,您需要让Angular的form> formsmodulengmodel绑定到工作。

如果您只有一个带有一个模块的应用程序,这很容易。只需在您的一个和唯一的xxx.module.ts文件中以下面的形式导入formsmodule

使用nz-switch的模块中

如果您正在使用具有多个模块的应用程序,则必须确保将其导入在中 >模块,在使用nz-switch的位置,在xxx.module.ts文件中:

import { FormsModule } from '@angular/forms`;

... 

@NgModule({
  declaration: [ ... ],
  imports: [ 
    ...,
    FormsModule
  ],
  ...

您应该很好。

Import FormsModule in the right module

While it doesn't say it in the documentation, you need to have Angular's FormsModule imported in order for the ngModel binding to work.

If you have an app with just one module, this is easy. Simply import the FormsModule as below in your one and only xxx.module.ts file.

If you're working on an app with multiple modules, you have to ensure you're importing it in the module where you're going to use the nz-switch

In that module, where you're using the nz-switch, in the xxx.module.ts file:

import { FormsModule } from '@angular/forms`;

... 

@NgModule({
  declaration: [ ... ],
  imports: [ 
    ...,
    FormsModule
  ],
  ...

You should be good to go.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文