我已经注入了storageService,但我试图在链接函数中使用this.storageService访问它的给定undefined。无法在角度打字稿中的指令中访问自定义工厂
任何人都可以帮助我吗?
module App.Directive {
import Services = Core.Services;
import Shared = Core.Shared;
export class UserNav implements ng.IDirective {
restrict = 'A';
require: any = "^?ngModel";
scope = true;
templateUrl: any = "template/user-nav.html";
link: ng.IDirectiveLinkFn = function(scope, element, attributes, ngModel: any) {
var a = this.storageService.getItem("userInfo", false);
console.log("getting > " + a);
}
constructor(public routerService: Services.RouterService,
public storageService: Services.StorageService) {
}
static factory(): any {
var directive = (routerService: Services.RouterService,
storageService: Services.StorageService) => {
return new UserNav(routerService, storageService);
}
directive['$inject'] = ['routerService', 'storageService'];
return directive;
}
}
}
有一个[方式如何指令](http://stackoverflow.com/q/33322282/1679310)可以创建一个示例和几个链接 –