0
ログイン後に許可されたリソースがサーバーからロードされる役割ベースのアクセス制御システムを実装しようとしています。生のJavaScriptコードを使用してチェックすることができました。角度型スクリプト指令のLinkメソッドが呼び出されない
angular.module('app').directive('accessControl',
[
'AuthService', function (authService) {
return {
restrict: 'A',
scope: "=",
link: function (scope, element, attrs) {
scope.canShow = function(resource) {
var allowedResources = authService.accountInfo.resources;
return allowedResources.indexOf(resource) !== -1;
}
}
}
}
]);
しかし、私のアプリケーション全体が活字体であることから、私は純粋な活字体でディレクティブを作成しようとしているが、残念ながら私はそうすることができません。ここに私のTSコードです。
export class AccessControl implements ng.IDirective {
public authService: App.AuthService;
public link: (scope: ng.IScope, element: ng.IAugmentedJQuery, attrs: ng.IAttributes) => void;
constructor(authService: App.AuthService) {
this.authService = authService;
console.log('authservice: ', authService);
AccessControl.prototype.link = (scope: ng.IScope, element: ng.IAugmentedJQuery, attrs: ng.IAttributes) => {
scope["canShow"] = function (resource: string) {
// some logic
console.log('can show' + resource);
return true;
};
};
}
public static factory(): ng.IDirectiveFactory {
var directive = (authService: App.AuthService) => {
return new AccessControl(authService);
};
directive['$inject'] = ['AuthService'];
return directive;
}
restrict = "A";
scope: "=";
}
angular.module('app').directive('accessControl', AccessControl.factory());
リンク機能が呼び出されません。 ヘルプやポインタは高く評価されます。