Xây dựng 1 ứng dụng Angular___BestPractice1
LEVEL UP!
Clean và Performant?
1) Sử dụng trackBy
Why?
<li *ngFor="let item of items;">{{ item }}</li>After:
// in the template
<li *ngFor="let item of items; trackBy: trackByFn">{{ item }}</li>
// in the component
trackByFn(index, item) {
return item.id; // unique id corresponding to the item
}2) Sử dụng const vs let
Why?
Before:
After:
3) Sử dụng Pipeable operators
Why?
Before:
After:
4) Isolate API hacks (Hash code để fix issue cho API) :)) có thể hiểu là vậy
Why?
Before:
After:
5) Subscribe in template
Why?
Before:
After:
6) Clean up subscriptions
Why?
Before:
After:
7) Use appropriate operators
Why?
Before:
After:
8) Lazy load
Why?
Before:
After:
9) Avoid having subscriptions inside subscriptions
Why?
Before:
After:
10) Avoid any; type everything;
Why?
Before:
After:
11) Make use of lint rules
Why?
Before:
After:
13) Small reusable components
Why?
Before:
After:
14) Components should only deal with display logic
Why?
Before:
After:
15) Avoid long methods
Why?
Before:
After:
16) DRY
Why?
Before:
After:
17) Add caching mechanisms
Why?
Before:
After:
18) Avoid logic in templates
19) Strings should be safe
Bigger picture
Last updated