我试图使用private http: Http
并且它给了我
error_handler.js:54 EXCEPTION: Uncaught (in promise): Error: DI Error
我在我的组件中使用http
component.ts
import { Component, OnInit } from '@angular/core';
import { FormBuilder, FormControl, FormGroup } from '@angular/forms';
import { Http} from '@angular/http';
import {Observable,Subscription} from 'rxjs/Rx';
import 'rxjs/add/operator/map';
import 'rxjs/add/operator/catch';
import { NouiFormatter } from 'ng2-nouislider';
import {NgbModule} from '@ng-bootstrap/ng-bootstrap';
@Component({
selector: 'app-char-maker',
templateUrl: './char-maker.component.html',
styleUrls: ['./char-maker.component.css']
})
export class CharMakerComponent implements OnInit {
constructor(
private formBuilder: FormBuilder,
private http: Http)
{
var obj;
}
ngOnInit() {
}
}
如果我在构造函数中评论private http: Http
,则错误消失。
我在这里失踪了什么?
答案 0 :(得分:1)
您需要在导入
下添加HttpModule
@NgModule({
imports: [
HttpModule
]
答案 1 :(得分:1)
对于Angular v 4.3
您可以使用HttpClientModule
。从
import {HttpClientModule} from '@angular/common/http';
并将其添加到您的导入
imports: [
HttpClientModule,
//... more code
]
For< V4.3 强>
您可以使用HttpModule
并从
import { HttpModule } from '@angular/http'
并将其添加到您的导入