我刚刚使用Angular material get started页面中的Angular2和Typescript启动了一个新项目。 一切正常,直到我使用来自' @ angular / http&#39 ;;的Http引入服务。 当ng服务正在运行时,我收到运行时错误,说Http不是NgModule 当我停止并重新运行服务时,我得到了一个编译错误: Http中的ERROR不是NgModule webpack:无法编译。
经过一番挖掘后,我尝试在根文件夹中添加index.ts并导出Http类,如下所示:
generate_board(Length, Width, Board) :-
length(Row, Width),
maplist(=([]), Row), % A row of empty lists, forming an empty row
length(Board, Length),
maplist(=(Row), Board). % A list of empty rows
| ?- generate_board(4,3, L).
L = [[[],[],[]],[[],[],[]],[[],[],[]],[[],[],[]]]
yes
| ?-
然后我执行了命令:
export {Http} from '@angular/http';
但没有效果。 我也试过
tsc -p .
这给出了几乎相同的错误: ERROR in Unexpected value' Http in C:/.... / myproject/node_modules/@angular/http/src/http.d.ts'由模块' AppModule导入C:/.... / myproject / src / app / app.module.ts' ./src/main.ts中的错误 找不到模块:错误:无法解析'。/ $ _ gendir / app / app.module.ngfactory' in' C:... \ myproject \ src' @ ./src/main.ts 4:0-74 @ multi ./src/main.ts
非常感谢任何帮助!
答案 0 :(得分:0)
您需要在app.module.ts中导入HttpModule并在Imports下使用HttpModule,例如,请参阅以下代码
import { HttpModule } from "@angular/http";
@NgModule({
imports: [
BrowserModule,
FormsModule,
HttpModule
],
declarations: [],
providers: [],
bootstrap: []
})
在服务中,您需要导入Http模块
import { Http, Response, Headers} from "@angular/http";
@Injectable()
export class Service {
Your Code......
}