angular tricks

Yet another 10 tricks that will help you develop a good application written in Angular

1. Enable Nginx gzip compression

 

 

2. Enable Nginx http2 support

 

 

3. Use this.zone.runOutsideAngular when you do complex calculations for a DOM and append them by this.zone.run when necessary.

 

4. Call Rust or C from Angular via WebAssembly to speed up your methods. See our blogpost to learn how to configure it: 5 easy steps to run your c-code from Angular App.

 

5. Use generics while carrying out operations on the array collection. It will help you avoid accidental typos or use a wrong type of assignments.

GOOD/RIGHT

 

BAD/WRONG

 

6. Enable https by Certbot. Follow instructions on https://certbot.eff.org/ site. It should add the following entries to your sites-enabled file

 

 

7. Do not enter any password to environment.ts file. Even if compiled by Webpack, your password will still appear in the code

 

 

Instead, create an API Endpoint with your credentials and restrict it to only one IP

 

 

8. By default you have installed Codelyzer but many of the rules are not included in the tslint.json file. Add these rules to improve your application:

 

 

9. Partial Type. When you use many implementations of a library in your app – for example my tables https://ngx-easy-table.eu/#/ 😉 – you don’t need to duplicate its config as many times as many components you have. Note, this is an experimental feature.

 

10. Mapped response. You can keep API endpoint params and responses in just one Object. For example, when you write tests or when you keep Domains in the separate modules. Note, this is an experimental feature.

 

See also: