I am creating a user model in typescript, with the following:
import {Inject} from 'angular2/core';
import {Http} from "angular2/http";
export class User {
firstName:string;
lastName:string;
constructor(User:User, @Inject(Http) private _http){
this.firstName = User.firstName;
this.lastName = User.lastName;
}
getUserFirstName(){
return this.firstName;
}
addUser(){
return this._http.post('/api/user/',this);
}
}
And in other places,I use:
var use = new User(userObject) // where userObject is an object with firstName and lastName
And this creates object, with two methods: getUsername
and addUser
.
However, there is an issue with injecting the http
. It is always undefined. Do you have any pointers or solutions to this problem?
Thanks