![](/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.