How to reuse angular components from different folders of the project?

28 views
Skip to first unread message

Rohan Chaudhary

unread,
Jan 14, 2019, 1:24:35 AM1/14/19
to Angular and AngularJS discussion

I am working on an Angular 6 project where the previous developers have copy / pasted components.


In this project mobile view is completely different from the desktop view, except some components and those components which could be reused, they are exactly copy/pasted by the developers. And even the '.ts' files of the different template views are also copy/pasted which could be reused.


Now I have two question

  • If I make a shared module and reuse that module in both the desktop and mobile folder does it have any impact on the speed / performance of the application as there are more than 50 components which needs to be done ?
  • Is it a standard to copy/paste code rather to reuse those components.?

You can get a clear picture of my question by seeing the attached image link below.https://ibb.co/DgT4rwh

Sander Elias

unread,
Jan 14, 2019, 1:51:11 AM1/14/19
to Angular and AngularJS discussion
Hi Rohan,

It's more common to reuse the components. It will probably make the entire payload of your app smaller. I don't think there is any speed difference.
If you are using the CLI you can split out mobile and desktop to different apps, but I think it is better to unify both with the use of some css selectors you can even drop off the difference. and make a unified app.

With the Angular CLI you can make libraries, you can move the shared code to such a library.

Regards
Sander
Reply all
Reply to author
Forward
0 new messages