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/http';
@Component({
viewProviders: [HTTP_PROVIDERS],
template: `
..//
<div class="col-md-6 col-md-offset-3 well">
<input type="button" class="btn btn-success btn-block"
(click)="get()" value="Fetch Users">
<hr>
<ul>
<li *ngFor="#user of users">
Id: {{ user.name }} | Name: {{ user.name }} | JSON: {{ user | json }}
</li>
</ul>
</div>
..//
export class Mov {
//Inicio test http
users: Array<Object>;
http: any;
//
//constructor(@Inject(HttpFactory) http) {
//constructor(http: Http) {
constructor(http: Http){
//
this.http = http;
}
get(){
this.http('resources/users.json')
.map(res => res.json())
.subscribe(users => this.users = users);
}
obtain this error:
EXCEPTION: Error during evaluation of "click"
ORIGINAL EXCEPTION: TypeError: this.http is not a function
anyone can tell me I'm doing wrong, I'm sorry for my English.