简体   繁体   English

找不到模块“@angular/forms”

[英]Cannot find module '@angular/forms'

I'm developing an Ionic 2/Angular app and I'm trying to use form validation following this tutorial: https://angular.io/docs/ts/latest/cookbook/dynamic-form.html我正在开发一个 Ionic 2/Angular 应用程序,我正在尝试按照本教程使用表单验证: https : //angular.io/docs/ts/latest/cookbook/dynamic-form.html

But the compiler says:但是编译器说:

Cannot find module '@angular/forms'.找不到模块“@angular/forms”。

Why is this modules not available?为什么这个模块不可用? Is it deprecated?它被弃用了吗?

I ran into the same problem, my solution was:我遇到了同样的问题,我的解决方案是:

1) add forms to the package.json: 1) 在 package.json 中添加表单:

"dependencies": {
...
"@angular/forms":   "0.2.0",
...
}

2) install using npm in the console, type within the app folder 2) 在控制台中使用 npm 安装,在 app 文件夹中输入

npm install

3) run app again 3)再次运行应用程序

npm start

Hope this helps希望这有帮助

Try npm install @angular/forms --save试试npm install @angular/forms --save

It will warn you that you should be using 2.0.0-rc.4 though.它会警告你你应该使用 2.0.0-rc.4。 This may come with it's own set of upgrade challenges...这可能伴随着它自己的一系列升级挑战......

Sometimes when updating versions I see messages like this:有时在更新版本时我会看到这样的消息:

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

I belive it can be due to file in use errors sometimes (I'm running Visual Studio on Windows as administrator).我相信这可能是由于文件使用错误有时(我在 Windows 上以管理员身份运行 Visual Studio)。

Make sure nothing is running that might have a file lock on any packages - such as angular CLI.确保没有运行任何可能对任何包有文件锁定的东西 - 例如 angular CLI。 So close any windows or processes and run something like npm install again.因此,关闭所有窗口或进程并再次运行npm install类的npm install

I had a weird situation where I can not do npm install, and had to copy the libs from shared path.我遇到了一个奇怪的情况,我无法进行 npm install,并且不得不从共享路径复制库。 Copy the "forms" folder under node_modules/@angaular solved the issue.复制 node_modules/@angaular 下的“forms”文件夹解决了这个问题。

The way to solve problem is: use cmd npm install @angular/forms --save解决问题的方法是:使用cmd npm install @angular/forms --save

and go to package.json double check make sure @angular/forms: "YOUR VERSION", => save it并转到 package.json 仔细检查确保@angular/forms: "YOUR VERSION", => 保存

reset the IDE tool and go back to app.module.ts remove and retype again.重置 IDE 工具并返回 app.module.ts 删除并再次重新输入。 it much be work.这很重要。

Thank You谢谢你

Is import { FormsModule } from '@angular/forms';从 '@angular/forms' 导入 { FormsModule } 吗? is injected in app.module.ts and added FormsModule array in the imports as below注入 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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM