【发布时间】:2016-09-22 21:27:13
【问题描述】:
我知道可以发custom structural directives。
<p *my-unless="someExpression">
但是,引号之间的表达式是通过计算得到的布尔值传入的
@Input() set myUnless(condition: boolean) {
console.log(condition);//either true, false, or undefined
}
我怎样才能做到,所以我只得到一个原始字符串值,如果我这样做了
<p *my-unless="some space delimted values">
我可以的
@Input() set myUnless(theString: string) {
console.log(theString);//=> theString == 'some space delimted values'
}
最终,我正在制定一个角色限制指令,其中允许的角色在属性值中声明,我在指令组件代码中进行检查,如
@Input()
set forRoles(allowedRoles: string) {
let userTypes = allowedRoles.split(' ');
if(~userTypes.indexOf(this.authenticatorService.getUserType())){
this.viewContainer.createEmbeddedView(this.templateRef);
} else {
this.viewContainer.clear();
}
}
也许结构指令对于这种事情是错误的?只是觉得我需要的任何地方的包装器组件都过大了。
【问题讨论】:
标签: angular