使用 formControlName 和 ngModel 的 angular 6 警告

编程入门 行业动态 更新时间:2024-10-23 14:34:36
本文介绍了使用 formControlName 和 ngModel 的 angular 6 警告的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

限时送ChatGPT账号..

我最近将 angular 版本升级到了 6-rc.我收到以下警告

I recently upgraded the angular version to 6-rc. I got following warning

看起来你在同一个表单域上使用 ngModel表单控件名称.支持使用 ngModel 输入属性和已弃用带有反应形式指令的 ngModelChange 事件在 Angular v6 中,将在 Angular v7 中移除

It looks like you're using ngModel on the same form field as formControlName. Support for using the ngModel input property and ngModelChange event with reactive form directives has been deprecated in Angular v6 and will be removed in Angular v7

有关这方面的更多信息,请在此处查看我们的 API 文档:https://angular.io/api/forms/FormControlName#use-with-ngmodel

For more information on this, see our API docs here: https://angular.io/api/forms/FormControlName#use-with-ngmodel

它具体说了什么?该链接没有 #use-with-ngmodel

What does it say exactly? the link does not have any fragment for #use-with-ngmodel

我想我需要删除 ngModel 并使用 formGroup 作为我的数据绑定对象.

I guess I need to remove ngModel and use formGroup as my data binding object.

推荐答案

如果您现在正在寻找 Angular 6 文档,请使用 https://next.angular.io

If you're looking for Angular 6 documentation right now then use https://next.angular.io

https://next.angular.io/api/forms/FormControlName#use-with-ngmodel

所以你有 3 个选择:

So you have 3 options:

使用响应式表单

use Reactive forms

使用模板驱动的表单

静音警告(不推荐)

imports: [
  ReactiveFormsModule.withConfig({warnOnNgModelWithFormControl: 'never'});
]

这篇关于使用 formControlName 和 ngModel 的 angular 6 警告的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

更多推荐

[db:关键词]

本文发布于:2023-04-21 09:47:25,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1000447.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:formControlName   ngModel   angular

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!