gpt4 book ai didi

javascript - Angular 5 StaticInjectorError :[Http]

转载 作者:行者123 更新时间:2023-11-30 11:27:08 27 4
gpt4 key购买 nike

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

StaticInjectorError[Http]: StaticInjectorError[Http]: NullInjectorError: 没有 Http 的提供者!在 NullInjector.get (core.js:923) 在 resolveToken (core.js:1211) 在 tryResolveToken (core.js:1153) 在 StaticInjector.get (core.js:1024) 在 resolveToken (core.js: 1211) 在 tryResolveToken (core.js:1153) 在 StaticInjector.get (core.js:1024) 在 resolveNgModuleDep (core.js:10585) 在 NgModuleRef.get (core.js:11806) 在 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

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

关于javascript - Angular 5 StaticInjectorError :[Http],我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47581094/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com