Best practices
The following are some of the best practices which one can adopt for developing Angular apps:
- Apply the single responsibility principle:
- Write one thing such as component, directive, service, and module per file
- Write small functions with a function doing just one thing
- Naming Convention:
- Use upper camel case for class names and interfaces. For example,
AppComponent,AppModule. - Use lower camel case for naming properties and methods.
- Avoid using underscore as a prefix for naming methods and properties.
- Match the class names with the file names in the following manner:
AppComponent-app.component.ts,BigAppComponent-big-app.component.ts,AppModule-app.module.ts,AppDirective -app.directive.ts,AppService-app.service.ts - Use custom prefixes for components and directives selectors.
- Use upper camel case for class names and interfaces. For example,
- Bootstraping: Put bootstraping logic in a file named
main.ts- Use Data Services: One should use data services for doing data operations such as making XHR calls, processing data with local storage, and...