角度es6でアプリケーションを開発しようとしています。私は監督に問題があります。 は、ここでの問題は、私は、コンストラクタ内のロール値を得ることができなかったです私のコードangularJS ES6指令
export default class RoleDirective {
constructor() {
this.template="";
this.restrict = 'A';
this.scope = {
role :"@rolePermission"
};
this.controller = RoleDirectiveController;
this.controllerAs = 'ctrl';
this.bindToController = true;
}
// Directive compile function
compile(element,attrs,ctrl) {
console.log("df",this)
}
// Directive link function
link(scope,element,attrs,ctrl) {
console.log("dsf",ctrl.role)
}
}
// Directive's controller
class RoleDirectiveController {
constructor() {
console.log(this.role)
//console.log("role", commonService.userModule().getUserPermission("change_corsmodel"));
//$($element[0]).css('visibility', 'hidden');
}
}
export default angular
.module('common.directive', [])
.directive('rolePermission',[() => new RoleDirective()]);
です。 は、ここで私は、このコンソール場合は、コントローラオブジェクトを取得します私のhtml実装
<a ui-sref="event" class="button text-uppercase button-md" role-permission="dfsd" detail="sdfdsfsfdssd">Create event</a>
です。しかし、this.roleを使用している間は結果は得られません。
[この回答](http://stackoverflow.com/a/41524591/2435473)も参照できます。 –
あなたはES5を使ってまったく同じ問題を抱えています。そして、このディレクティブが最初にコントローラーと分離スコープを持つことは意味がありません。 – zeroflagL