![](/img/trans.png)
[英]How to sync my template and typescript code in angular reactive forms, having form groups?cannot find control error
[英]Cannot find module '@angular/forms'
我正在开发一个 Ionic 2/Angular 应用程序,我正在尝试按照本教程使用表单验证: https : //angular.io/docs/ts/latest/cookbook/dynamic-form.html
但是编译器说:
找不到模块“@angular/forms”。
为什么这个模块不可用? 它被弃用了吗?
我遇到了同样的问题,我的解决方案是:
1) 在 package.json 中添加表单:
"dependencies": {
...
"@angular/forms": "0.2.0",
...
}
2) 在控制台中使用 npm 安装,在 app 文件夹中输入
npm install
3)再次运行应用程序
npm start
希望这有帮助
试试npm install @angular/forms --save
它会警告你你应该使用 2.0.0-rc.4。 这可能伴随着它自己的一系列升级挑战......
有时在更新版本时我会看到这样的消息:
npm ERR! errno -4048
npm ERR! syscall rename
npm ERR! Error: EPERM: operation not permitted, rename 'R:\TFS\RRCRM\RRCRM\node_modules\@angular\forms' -> 'R:\TFS\RRCRM\RRCRM\node_modules\@angular\.forms.DELETE'
npm ERR! at Error (native)
npm ERR! { [Error: EPERM: operation not permitted, rename 'R:\TFS\RRCRM\RRCRM\node_modules\@angular\forms' -> 'R:\TFS\RRCRM\RRCRM\node_modules\@angular\.forms.DELETE']
npm ERR! errno: -4048,
npm ERR! code: 'EPERM',
npm ERR! syscall: 'rename',
npm ERR! path: 'R:\\TFS\\RRCRM\\RRCRM\\node_modules\\@angular\\forms',
npm ERR! dest: 'R:\\TFS\\RRCRM\\RRCRM\\node_modules\\@angular\\.forms.DELETE',
npm ERR! parent: 'rrcrm' }
npm ERR!
npm ERR! Please try running this command again as root/Administrator.
npm ERR! Please include the following file with any support request:
npm ERR! R:\TFS\RRCRM\RRCRM\npm-debug.log
我相信这可能是由于文件使用错误有时(我在 Windows 上以管理员身份运行 Visual Studio)。
确保没有运行任何可能对任何包有文件锁定的东西 - 例如 angular CLI。 因此,关闭所有窗口或进程并再次运行npm install
类的npm install
。
我遇到了一个奇怪的情况,我无法进行 npm install,并且不得不从共享路径复制库。 复制 node_modules/@angaular 下的“forms”文件夹解决了这个问题。
解决问题的方法是:使用cmd npm install @angular/forms --save
并转到 package.json 仔细检查确保@angular/forms: "YOUR VERSION", => 保存
重置 IDE 工具并返回 app.module.ts 删除并再次重新输入。 这很重要。
谢谢你
是从 '@angular/forms' 导入 { FormsModule } 吗? 注入 app.module.ts 并在导入中添加 FormsModule 数组,如下所示
app.module.ts
import { BrowserModule } from '@angular/platform-browser';
import { NgModule } from '@angular/core';
import { FormsModule } from '@angular/forms';
imports: [
BrowserModule,
FormsModule
]
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.