TypeError: Cannot read property 'post' of undefined

心不动则不痛 提交于 2019-12-06 02:26:33

Just by declaring public http: Http will not make Http provider instance available inside component. You have to inject http service inside constructor, that will bring http object.

public constructor(
    private marginService: MarginServcies, 
    private http: Http //<-- added Http service.
) {
 //your code as is
}

Remove the declaration of public http: Http(http declaration) from start of class public http: Http

Http is an Inbuilt Angular Provider from the angular http module

import { Http, Response } from '@angular/http';

So you have to inject this http service in to the constructor. Then Only angular framework resolve the dependency

export class YourService {
    constructor(private http: Http) {

    }
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!