我在我的typescript控制器中使用$q.defer时遇到问题。我得到的错误是this.$q.defer不是一个函数。这是我的打字稿...
export class AccountWizardController implements IAccountWizardScope {
account: Account;
static $inject = ['$q']
constructor(private $q: ng.IQService) {
}
saveState(): ng.IPromise<Account> {
console.log(this.$q);
var deferred = this.$q.defer<Account>();
console.log(deferred);
return deferred.promise;
}
}
export interface IAccountWizardScope {
account: ContractMonitor.Models.Account;
saveState(): ng.IPromise<Account>;
}
当我在视图中调用saveState()方法时,我得到了错误。这让我大惑不解。
谢谢。
发布于 2015-07-15 10:16:42
$q
一直拥有defer
(ref)。所以我猜测this.$q
是undefined
,这是因为您使用了错误的this
。修复,使用胖箭头来保留上下文:
saveState = (): ng.IPromise<Account> => {
console.log(this.$q);
var deferred = this.$q.defer<Account>();
console.log(deferred);
return deferred.promise;
}
https://stackoverflow.com/questions/31420373
复制相似问题