Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to tell when to create a new component?

I've been looking around behind the logic of when someone shall create a new component in a web application on angularjs / angular but I suppose this is more general and might apply on all component based front end frameworks.

I know that there are some principles like it should be abstract and reusable but e.g. I have seen on angular docs that each separate route looks at a specific component (how can this be reusable). Is there any solid question which I might ask before creating a new component ?

like image 453
korteee Avatar asked Sep 13 '17 08:09

korteee


People also ask

What should be a component in Angular?

What are Angular components? A component is a directive with a template that allows building blocks of a UI in an Angular application. Components will always have a template, a selector, and may or may not have a separate style. Components are declared using @Component.

How many new files are created and updated when you create a new component using CLI?

CLI Component Generation It looks like the CLI automatically created the new folder to hold our new component in app/virtual-machines . In addition we see four new files associated with the automatically generated component.

How many files will get created when the following command is executed to generate a component using Angular CLI Ng generate component Mycomponent?

It will create the following 4 files: componentname. css. componentname.


1 Answers

In order to make a decision whether you have to create a component or not, i think you have to answer the following questions:

  1. Is it possible for your code chunk to be reused? If yes, construction of a new component seems like a great idea.
  2. Is your code quite complex? If yes maybe its good idea to split in separate components in order to make your code more readable and maintainable.
like image 166
teonapster Avatar answered Oct 20 '22 00:10

teonapster