@ angular / forms / FormsModule缺失

时间:2016-08-26 13:51:47

标签: angular

我正在尝试从Angular 2 RC5中的@ angular / forms @ 0.3.0导入FormsModule。应该简单吧?

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

但是,这不是我使用

安装的@ angular / forms库的一部分
npm install @angular/forms

有些人建议使用:

import { ReactiveFormsModule }   from '@angular/forms';

然而,这也不起作用。

我已经查看了表单包,它似乎在form_providers输入文件(form_providers.d.ts)中,它确实提到了FormsModule。在forms.js中,它提到__export(require(' ./ form_providers'));所以这意味着它应该可用吗?

我是如何解决这个问题的?

非常感谢

JT

app.module.ts

import {NgModule} from '@angular/core';
import {FormsModule}   from '@angular/forms';
import {BrowserModule} from '@angular/platform-browser';
import {platformBrowserDynamic} from '@angular/platform-browser-dynamic';
import {MeteorModule} from 'angular2-meteor';
import {AppComponent} from './app.component';


@NgModule({
    imports: [BrowserModule, MeteorModule, FormsModule],
    declarations: [AppComponent],
    bootstrap: [AppComponent]
})
export class AppModule { }

platformBrowserDynamic().bootstrapModule(AppModule,[ disableDeprecatedForms(),provideForms()]));

Package.json (由" npm install&#34使用;)

{
  "name": "angular2-meteor-base",
  "private": true,
  "scripts": {
    "start": "meteor run",
    "test": "meteor test --driver-package practicalmeteor:mocha",
    "test:ci": "meteor test --once --driver-package dispatch:mocha-phantomjs"
  },
  "devDependencies": {
    "chai": "3.5.0",
    "chai-spies": "0.7.1"
  },
  "dependencies": {
    "@angular/common": "^2.0.0-rc.5",
    "@angular/compiler": "^2.0.0-rc.5",
    "@angular/core": "^2.0.0-rc.5",
    "@angular/forms": "latest",
    "@angular/platform-browser": "^2.0.0-rc.5",
    "@angular/platform-browser-dynamic": "^2.0.0-rc.5",
    "@angular/router": "^3.0.0-rc.1",
    "angular2-meteor": "latest",
    "angular2-meteor-auto-bootstrap": "latest",
    "angular2-meteor-polyfills": "latest",
    "angular2-meteor-tests-polyfills": "latest",
    "es6-shim": "0.35.1",
    "lodash": "^4.15.0",
    "meteor-node-stubs": "0.2.3",
    "reflect-metadata": "0.1.3",
    "rxjs": "5.0.0-beta.6",
    "zone.js": "0.6.12"
  }
}

app.component.ts

import {Component} from '@angular/core';


@Component({
  selector: 'app',
  template: 'Hello World'
})

export class AppComponent {

  constructor() {
  }
}

3 个答案:

答案 0 :(得分:0)

我有类似的问题,不得不更新我的package.json以指定以下表单的版本:

"@angular/forms": "^0.3.0",

之后运行npm更新。

答案 1 :(得分:0)

确保将FormsModule添加到正在使用的应用模块或模块中,然后重新启动服务器。

答案 2 :(得分:0)

我只需执行以下步骤即可解决该问题:

  • 从“ @ angular / forms”写导入{};
  • 然后,在 {}
  • 中编写 FormsModule
  • 最后在导入
  • 中编写 FormsModule

有效。