1

I am on learning phase of angular4. Now creating single app. but want to know which is better, templating or better to work via component for each modules?

5
  • 1
    You may want to read this. angular.io/guide/styleguide Commented Aug 28, 2017 at 6:53
  • Yes, i have read this. What will you prefer? Commented Aug 28, 2017 at 6:58
  • Use external *.html template files. Don´t put HTML code into the component. If thats the question. You may want to have a look at Angular CLI since this applies the styleguide in most cases. Commented Aug 28, 2017 at 7:05
  • what do you mean by templating? Commented Aug 28, 2017 at 9:56
  • 1
    I have tried with making separate for each page or modules like this. prntscr.com/geak62 But developer used template for dom element instead of templateUrl So asking which is better? Commented Aug 29, 2017 at 3:28

1 Answer 1

1

Why? One component per file makes it far easier to read, maintain, and avoid collisions with teams in source control.

Why? One component per file avoids hidden bugs that often arise when combining components in a file where they may share variables, create unwanted closures, or unwanted coupling with dependencies.

Why? A single component can be the default export for its file which facilitates lazy loading with the router. for more details https://angular.io/guide/styleguide

So the Conclusion is if you have modular structure it will help you to easily understand and easy maintainable as your application grows big. So it is recommended to follow these coding practices to avoid any issues while your are in mid developing phase.

Sign up to request clarification or add additional context in comments.

4 Comments

Thanks mate... Module structure means like this way, right? prntscr.com/geak62
Yes, but if you still have some questions about structure then you can refer some of the ongoing open source projects of angular 2 like github.com/aviabird/angularspree
I have tried from this repo. github.com/preboot/angular-webpack How can i use angular cli on existing project?
Install Angular 2 cli globally and generate new project through angular cli command then it will automatically setup webpack with angular 2. Follow steps in Angular quick start angular.io/guide/quickstart . Here is angular cli documentation cli.angular.io