How to instantiate and apply directives programmatically?

后端 未结 1 1598
悲&欢浪女
悲&欢浪女 2020-11-27 07:52

I know that in ng2 we have ComponentFactoryResolver that can resolve factories that we can apply to a ViewContainerRef.

But, is there somet

相关标签:
1条回答
  • 2020-11-27 08:48

    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.

    0 讨论(0)
提交回复
热议问题