1
我在我的項目中使用TypeScript,我無法將屬性分配給任何東西。我試圖從服務中獲取一些數據並將其分配給使用構造函數聲明的私有對象。但是,我不斷收到相同的錯誤:TypeError:無法在這裏[某些數據]上創建屬性[某些屬性]。 這裏是我的代碼:Typescript:不能在函數內創建屬性
module MyModule.Controllers {
"use strict";
export interface ICurrentUser {
DisplayName: string;
Features: string[];
}
export class DashboardController {
authenticationService = new Services.AuthenticationService(this.$http);
static $inject = ["$http"];
constructor(private $http: ng.IHttpService, private currentUser: ICurrentUser, private currentUserFeatures: string[])
{
this.getCurrentUser();
this.getUserGroupForCurrentUser();
return;
}
getUserGroupForCurrentUser =() => {
this.authenticationService.getUserGroupForCurrentUser().then((authenticationId) => {
this.currentUser.Features = authenticationFeatures;
});
}
getCurrentUser =() => {
this.authenticationService.getCurrentUser().then((user) => {
this.currentUser.DisplayName = userName;
});
}
}
}
需要得到的實際錯誤 –
TypeError:無法在字符串'John Doe'上創建屬性'DisplayName' – user1789573
我無法弄清楚。看起來像'this.currentUser.DisplayName = userName;'雖然是問題的根源。也許'this.currentUser'不是'ICurrentUser'對象,是別的,因爲它在承諾中? –