2017-04-04 82 views
1

我的组件文件包含:Angular2打字稿 - 错误TS2307:找不到模块 'angular2 /表格'

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

 
@Component({ 
 
    selector: 'my-app', 
 
    template: `<user></user> 
 
    `, 
 
}) 
 
export class AppComponent { 
 

 
}

我app.modules:

import { NgModule }  from '@angular/core'; 
 
import { BrowserModule } from '@angular/platform-browser'; 
 
import { FormsModule } from '@angluar/forms'; 
 
import { AppComponent } from './app.component'; 
 
import { UserComponent } from './components/user.component'; 
 

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

当我尝试编译我的代码我得到这个错误:错误TS2307:找不到模块'angular2/forms' 谢谢!

+0

请添加你的package.json文件,我认为你只是缺少@ angular/forms作为依赖关系。 – Supamiu

+0

他已经存在于package.json中 – Aminfo

+0

您是否正在使用angular-cli? webpack或system.js?是“node_modules/@ angular”中存在的文件夹“形式”?您是否安装了 – Supamiu

回答

2

你有一个错字:

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

应该是:

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

PS。我假设你已经写了错误信息,因为角度正确拼写在那里;) – Alex

0

你在你的代码
检查新的位置错误:

import { NgModule }  from '@angular/core'; 
 
import { BrowserModule } from '@angular/platform-browser'; 
 
import { FormsModule } from '@angular/forms'; 
 
import { AppComponent } from './app.component'; 
 
import { UserComponent } from './components/user.component'; 
 

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

+0

eeh,这与我的回答有什么不同? :D你刚刚做了和我一样的改变;) – Alex

+0

真是巧合! – newpeople

相关问题