Angular Directives vs Components

“Custom directive?Or should this be better put as a component?”
This question haunts a lot of people who work with angular.They find this a confusing loop where both can be used to achieve something ,but the voice saying ‘Tis is thy right path’ has not developed yet.
The best way to decide would probably be to consult someone who has experience.
Else use these rules –
Unless the changes brought about are very small use components.
Let me break this down to two further rules –
Use directives to bring about small changes late in the game.
Use components to model larger changes.
Last rule of thumb?
Stop using directives early in development.Use them later, when changing the component will have unneeded consequences.
Why am I advocating using components so strongly?
Components allow easier customization as they are more flexible, easier customization is allowed.
Components can also be mixed with other components, i.e. using child components, certain behaviors can be easily created and customized.
Except for which are provided by angular i.e. ngFor, ngIf etc ,custom made directives should only be used so as to add necessary features to a component, when changing the component will have side effects
Knowing these rules will probably save you time debating with yourself.

 

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s