Posted on: January 28, 2022 Posted by: rahulgite Comments: 1,087
Angular Best Practices

Angular Best Practices

  • Use ES6 features like let, const, arrow function
  • Use trackby along with ngFor
  • Use lazy loading
  • Use index.ts file for shorter import
  • use datatype, Avoid ‘any’ type
  • Create own Data type using Interface
  • Avoid memory leak by unsubscribing the observable also we can use Rxjs operator  like takeUntil()
  • Should use Async pipe
  • Avoid logics in the template
  • Use Environment variable for multiple server or API call configurations
  • Use module structure
  • Focus on small and reusable components
  • Declaring a variable with ‘const’ if the value is not changing
  • Use smart and dumb Components strategies
  • Using immutability should use spread (…)operator
  • safe navigation operator
  • Use route guard on navigation
  • Use AOT compilation
  • Documentation in code like:-
/**
* This is the get function
* @param age This is the age parameter
* @returns returns a string version of age
*/
function getAge(age: number): string {​​​​​​​
return age.toString();
}​​​​​​​

More Angular Notes

Angular Docs

Loading

Comments are closed.