【发布时间】:2016-03-14 10:52:36
【问题描述】:
我正在 typescript 中创建一个用户模型,其中包含以下内容:
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);
}
}
在其他地方,我使用:
var use = new User(userObject) // where userObject is an object with firstName and lastName
这会创建对象,有两种方法:getUsername 和 addUser。
但是,注入http 存在问题。它总是未定义的。您对这个问题有任何指示或解决方案吗?
谢谢
【问题讨论】:
标签: typescript angular