Answer the question
In order to leave comments, you need to log in
Who feeds into Http constructor or how to use providers?
Made a constructor accepting Http, but where to serve it? How to use providers? When I included just "Http" as the provider, and used the constructor with no arguments, the http object was available, but there was no effect.
import {
Component,
NgModule
} from '@angular/core';
import {
Http
} from '@angular/http';
import 'rxjs/add/operator/map'
import {
HttpModule
} from '@angular/http';
@Component({
selector: 'my-app',
providers: [HttpModule],
template: `<h1>Test {{teste}}</h1>
<table>
</table>
`
})
@NgModule({
imports: [HttpModule]
})
export class AppComponent {
teste: string;
constructor(private http: Http) {
this.teste = "ttttttttt";
this.http.get('URL')
.map(res => res.json())
.subscribe(data => {
this.teste = data;
});
}
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question