简体   繁体   中英

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 ....
        }
    }
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM