我试图创建一个ngIf工程控制指令,如果用正确的权限的用户被允许看到具体的内容,这样的事情:指令,它作为NG-IF(角2)
<div [type-of-user]="load data from the user and check it (normal or premium)">
<h3>You are allow to see this.</h3>
</div>
我读到有关如何做到这一点,并在此doc关于“属性指令”,但我仍然无法实现它发现(我是新与角2)
到目前为止,我有这样的:
import {Directive, ElementRef, Input} from '@angular/core';
@Directive({
selector: '[type-of-user]'
})
export class TypeOfUserDirective{
constructor(private el: ElementRef){}
@Input('type-of-user') userControl: string;
private haspermission(permission: string) {
/*the style background color is just to test if works*/
this.el.nativeElement.style.backgroundColor = permission;
}
}
我已经在app.module中添加了指令。
任何意见如何继续将是伟大的。
..检查[* ngIf](https://angular.io/ docs/ts/latest/guide/template-syntax.html#!#ngIf) –
指令用于修改用户内容,所以尝试向指令注入一些内容并对其进行修改。 –
感谢您的建议,最后我可以编辑一下我发现的有关指令和文章的plunkr。 @RomanC –