I\'m trying to use the following code after trying several ways online tutorials I can not make it work.
..//
import {Http, HTTP_PROVIDERS} from \'angular2/h
Seems like somehow Http
isn't get injected correctly. Use @Inject
to inject Http
dependency.
import { Component, Inject} from 'angular2/core';
//above code should be at start.
constructor(@Inject(Http) http: Http) {
@Inject
is needed for acquiring dependency when not using Typescript for transpilation of JS.
Well, as the error message states this.http
is not a function, it's an object which has several methods. You need this.http.get()
method:
this.http.get('resources/users.json')
.map(res => res.json())
.subscribe(users => this.users = users);