[英]How can we apply custom directive conditionally in angular 6 when using node projection with <ng-container></ng-container>?
I am trying to apply custom directive based on some condition in angular reactive form.But I have not find any way to implement this feature. 我正在尝试根据角度反作用形式的某些条件应用自定义指令。但是我找不到任何实现此功能的方法。 Structural directive is not working in node projection. 结构指令在节点投影中不起作用。
<input
type="text"
*customDirective="data"
// directive1 /directive2
// I have to apply above directive based on some condition
/>
Try this: 尝试这个:
@Directive({
selector: '[customRequired]'
})
export class CustomRequired {
@Input() customRequired: boolean;
@HostListener('change', ['$event'])
onCall(event) {
if(this.customRequired) {
// code to be done ....
}
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.