No, directives can't be added or removed dynamically. They are only applied to HTML statically added to component templates.
What you could do is to enable/disable the directive by passing a parameter (@Input()
) to the directive to notify it to do something or not.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…