Module not found: Error: Can't resolve '@angular/http' even i used import {HttpClientModule} from '@angular/common/http';
Run Code Online (Sandbox Code Playgroud)
在根应用程序模块中
import { BrowserModule } from '@angular/platform-browser';
import { HttpClientModule } from '@angular/common/http';
@NgModule({
imports: [
BrowserModule,
// import HttpClientModule after BrowserModule.
HttpClientModule,
],
declarations: [
AppComponent,
],
bootstrap: [ AppComponent ]
})
export class AppModule {}
Run Code Online (Sandbox Code Playgroud)
为您服务
import { Injectable } from '@angular/core';
import { HttpClient } from '@angular/common/http';
@Injectable()
export class ConfigService {
constructor(private http: HttpClient) { }
getConfig() {
return this.http.get(this.configUrl);
}
}
Run Code Online (Sandbox Code Playgroud)
在你的组件中
showConfig() {
this.configService.getConfig()
.subscribe((data: any) => {
// response...
});
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
15459 次 |
| 最近记录: |