本文介绍了Angular 5 StaticInjectorError:[Http]的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好,我收到这样的错误,这是什么原因?

hello i am getting such an error what is the reason for this?

StaticInjectorError [Http]:StaticInjectorError [Http]:NullInjectorError:没有Http的提供程序!在tryResolveToken(core.js:1153)的resolveToken(core.js:1211)的NullInjector.get(core.js:923)处,在resolveToken(core.js :)的StaticInjector.get(core.js:1024)处输入代码1211)在tryResolveToken(core.js:1153)在StaticInjector.get(core.js:1024)在resolveNgModuleDep(core.js:10585)在NgModuleRef.get(core.js:11806)在resolveDep(core.js:12302) )

StaticInjectorError[Http]: StaticInjectorError[Http]: NullInjectorError: No provider for Http! at NullInjector.get (core.js:923) at resolveToken (core.js:1211) at tryResolveToken (core.js:1153)enter code here at StaticInjector.get (core.js:1024) at resolveToken (core.js:1211) at tryResolveToken (core.js:1153) at StaticInjector.get (core.js:1024) at resolveNgModuleDep (core.js:10585) at NgModuleRef.get (core.js:11806) at resolveDep (core.js:12302)

import { Injectable } from '@angular/core' import {Todo} from './Todo'

import {Http, Response,Headers,RequestOptions} from '@angular/Http' import {Observable} from 'rxjs/Observable' import 'rxjs/add/operator/do' import 'rxjs/add/operator/catch' import 'rxjs/add/operator/map'

@Injectable() export class TodoService{

constructor(private http: Http){}

todoUrl = "https://jsonplaceholder.typicode.com/todos";

getTodos():Observable{ return this.http.get("https://jsonplaceholder.typicode.com/todos") .map((res:Response)=>res.json()) .do(data=>console.log("TODOS LIST")) } }

推荐答案

尝试在app.module.ts中导入HttpClientModule

Try to import HttpClientModule in your app.module.ts

import { HttpClientModule } from '@angular/common/http';

这篇关于Angular 5 StaticInjectorError:[Http]的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-22 20:17