Coding with Angular - Tips and Tricks
source link: https://hijiangtao.github.io/2020/04/29/Coding-with-Angular-Tips-and-Tricks/
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
当你第一次从其他框架切换到 Angular 是否会有些迷茫,在感叹框架大而全的同时却对其中很多概念不尽了解?近期,为了给不断加入团队的新同学营造一个快速上手的环境,于是把团队的项目代码仔细阅读了一遍,从中挑出了一些在大家提交代码中反复会「犯的错误」,并总结成一系列值得 Angular 新手注意和学习的一些最佳实践。
本分享共分为三个部分,首先会从中后台系统中最经典的部分——响应式表单开始,介绍表单在验证、控制可用性中的一些优化用法和避免死循环的建议,然后第二部分着重从书写规范和编码建议给出了一些用例、以方便大家在日后的开发过程中能有更好的 Code Review 体验,分享的最后一章会就 Angular 项目构建优化给出一些建议。
以下为分享大纲:
- Reactive Forms
- Control Validation
- Infinite Loops
- Control Disabling
- Clean code
- Variable and function names
- Code comments
- Subscribe in templates
- Memory leaks
- Imports with path aliases
- Optimization
- Lazy Loading for main bundle
- Bundle Analyzer
- Lazy Loading for images
- Virtual Scrolling
- Fonts, etc.
注:本分享中提及的虚拟滚动意指 CDK,但未展开分享,感兴趣的同学可以自行搜索相关资料了解。
参考
- https://netbasal.com/angular-reactive-forms-tips-and-tricks-bb0c85400b58
- https://itnext.io/clean-code-checklist-in-angular-%EF%B8%8F-10d4db877f74
- https://itnext.io/how-to-optimize-angular-applications-99bfab0f0b7c
- https://blog.bitsrc.io/lazy-loading-images-using-the-intersection-observer-api-5a913ee226d
- https://developer.mozilla.org/en-US/docs/Web/API/Intersection_Observer_API
- https://github.com/webpack-contrib/webpack-bundle-analyzer
Recommend
-
80
One of my latest assignments was to develop a custom drop-down component which supports both single and multiple selections. As always, I will share some tips with you in the hope that you will learn new things.
-
66
I’ve compiled a list of my favorite GitHub tips and tricks that I use in my workflow daily. You might be familiar with some or even all of them, but I find that developers new to GitHub and veterans alike might pick up a...
-
23
Angular comes with so many features, both popular and unknown, the easiest way to discover tricks to achieve difficult tasks using Angular is to use Angular a lot more and learn in the process. Here are my favorite Angula...
-
41
12 useful NPM tips and tricks for more productive JavaScript coding.
-
12
iPad Tips & Tricks Tips and Tricks: iPadOS 13.4 Trackpad and Mouse Settings
-
13
Tips and Tricks: Managing iOS 13 Bluetooth App Access Settings If you recently upgraded to iOS 13, you may have noticed some new...
-
17
Tips and Tricks: The iPadOS Floating On-Screen Keyboard If I...
-
29
This is more of a note for myself. Over time, I’ve learned some useful fact about ROOT that I now wish I have known when I started using ROOT. Hopefully as a ROOT user, you could also find some of these helpful. Tell ROOT to not s...
-
11
Python Tips and Tricks Python Tips and Tricks...
-
11
Oct 13, 2019 - 7 minute read - Comments - burp
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK