SlideShare a Scribd company logo
SAARE JAHAAN SE ACHHA HINDSUTAN HUMARA
Top 7 Angular
Best Practices
to Organize
Your Angular
App
www.bacancytechnology.com
Angular is a JavaScript framework widely
used to make web apps, truly native apps
and especially SPAs, efficiently. Angular has
been designed in a way to overcome the
limitations of other frameworks. With its
dynamic features, you can create the best
web apps with optimized speed and
performance. The interactive tools offered
by the Angular framework outdoes the
features of other existing frameworks. Once
you are developing your project using
Angular, there’s no need to rely on other
third-party libraries. Despite all the
compelling features offered by Angular, if
you overlook your coding practices for the
Angular code, there are chances of facing
performance issues.
Maintaining your code is very important,
not only for Angular but any other
framework, because it directly affects the
output, and you surely don’t want a clumsy
web app. In this blog – we will discuss
Angular best practices to improve your
Angular app performance instantly. Get
knowledgeable on how to refine your
Angular code with a clean code checklist in
Angular.
Angular Best
Practices to
Improve Your
Angular App
Performance
Whenever there’s a need to generate
different templates for each item from the
collection, we use the built-in Angular
directive – ngFor.
< ul >
< li *ngFor="let item of items;">{{item.id}}<
/li >
< /ul >
1. Make Use of trackBy
Now, let’s see what the problem with ngFor
is. Suppose we need to change the iterative
data due to some requirements. In that case,
it will cause the problem as Angular doesn’t
keep any record of the data being iterated
and is unaware of the data being added or
removed. For implementing this, Angular
releases all the DOM elements related to the
collection and adds them again. And we all
know how expensive DOM manipulations
can be when dealing with a massive
collection of data.
To avoid this costly manipulation, we can
use trackBy. The use of trackBy is
considered one of the optimum techniques
to be followed. It gives a unique identifier to
each item of the collections, and thus the
render process of the whole DOM can be
avoided.
@Component({
selector: 'demo-app',
template: `
< ul >
< li *ngFor="let item of items;trackBy:
trackByFunc">{{item.id}}< /li >
< /ul >
< button (click)="getAllItems()">Click to
Refresh< /button >
`,
})
export class DemoApp {
constructor() {
this.items = [{id: 10}, {id: 20}, {id: 30}];
}
getAllItems() {
this.items = this.getAllItemsFromServer();
}
getAllItemsFromServer() {
return [{id: 10}, {id: 20}, {id: 30}, {id: 40}];
}
trackByFunc(i, item) {
return item.id; // or i
}
}
It’s quite necessary but considered the best
way to keep your component separate from
your logic. I have seen many developers
mixing the components and business logic;
making it too complicated and messy to
understand. And that’s why it is advisable
to use the logic in a separate service.
2. Try Avoiding the Use of
Logic in the Component
Testing user interface and components
is treated differently and is quite tricky
compared to logic testing. And that’s
why you should have separate services
for component and business logic.
Different services for business logic
improves code quality and reusability.
When you have your logic in your
separate service, you can use that
service in multiple components. And
this way, the code coverage Angular
decreases and eventually the build size
too. You can reuse the code to write less
code.
Here are the reasons for
avoiding the use of logic in
the Angular coding
standards –
It indeed enhances the code review,
readability, neatness of the code, and
performance of the high-scale
application.
3. Use of Lazy Loading
The use of Lazy Loading can help you
increase the performance and productivity
of your application. Lazy Loading is a built-
in feature that allows Javascript to load the
component asynchronously whenever that
particular route hits. it divides the entire
app into various bundles to manage its
speed. So, all the components related to the
active route will be loaded.
Lazy Loading in Angular is used only at the
start of the application. Once the
application begins and the user starts
navigating, it will load immediately.
(1) In your app routing file, use loadchildren
rather than a component.
const routing: Routes = [
{
path: 'items',
loadChildren: () =>
import('./data/data.module').
then(d => d.DemoModule)
}
];
Visit Angular documentation and explore
more regarding its features.
Here is the Primary
Implementation in Your
Angular Modules Best
Practices-
const routing: Routes = [
{
path: '',
component: DemoComponent
}
];
Now, add the route of that particular
component in the routing module for the
Lazy Loaded module.
Observable Memory Leaks are commonly
noticed in almost all frameworks and
libraries.
Angular also has the same issue. Angular
Observables mainly streamlines whole data,
but memory leaks can be caused if you are
not attentive enough. Memory Leaks are
one of the severe and harmful problems
attacking the application’s security. Here
are some suggestions to secure your
application –
– Use of async pipe
You can use an async pipe and promise to
prevent memory leaks. You should try your
best to avoid subscribing to observables and
then binding them with the components.
4. Prevent Memory Leaks
So, the conclusion is if the observable
technique is not entirely done, the chances
of memory leaks are likely to occur.
– Use of take(1)
take(1) is an operator. It takes the value and
allows for not subscribing whenever a new
value is diagnosed. It takes care that you
receive data only once. It prevents leaking
of memory in an efficient way.
info$.pipe(take(1)).subscribe((response)=>co
nsole.log(response))
– Use of takeUntil
takeUntil is also an operator. It allows
monitoring the Observables and get rid of
the subscriptions once the value is emitted
by Observables. We can conclude that it
secures the Observables from getting
leaked.
export class DemoApp implements OnInit,
OnDestroy {
constructor(private route: ActiveRoute,
private http: Http) {
}
ngOnInit() {
this.route.params
.takeUntil(destroyedComp(this))
.subscribe(param => {
// write code here...
});
this.http.get("/loading")
.takeUntil(destroyedComp(this))
.subscribe(res => {
// write code here...
});
}
ngOnDestroy() {
// empty
}
}
At the time of Angular code review, I have
observed many developers using ‘any’ as
variable types, which is not one of the
Angular best practices. The thing with ‘any’
is that Angular will assume the variable’s
type based on that particular variable’s
value. So, you have to be doubly sure when
you use ‘any’ to declare a variable, or else it
could cause some small bugs that can be
hard to debug.
Let’s take an example here –
If you have this code.
5. Declaring Variable Types
Rather Than Using any
let a = 10;
let b = 'xyz';
let c = a + b;
console.log(`Value of c: ${z}`
// Output
Value of c: 10xyz
In the above code, the output will be as
expected.
But, if you have code like this –
let p: number = 10;
let q: number = 'xyz';
let r: number = a + b;
// compile error:
Type '"xyz"' is not assignable to type
'number'.
let s: number
You might not get the expected value all the
time. To avoid that, you can use number
instead of any.
6. Angular Coding
Practices and Folder
Structure
Most of the developers tend to overlook the
importance of standard coding practices.
But, very few realize that following the code
styles can help their fellow developers for
code review quickly and adequately. It is
not just for Angular; you should try to
follow the coding practices in any
programming language you are using. It
increases the understandability, readability,
simplicity, and adaptability of your project.
Here are some coding
standards you can keep in
your mind –
Every single file should have code lines
within 400.
Every single function should have the
code lines within 75.
For different slider components, use a
custom prefix.
Utilize const if the values are constant
throughout the file.
Names of functions should be
meaningful and in the lower camel case.
Always have a habit of leaving an empty
line between all the imports and
modules; once you are done
importing all the third-party
applications, leave a blank line and then
start with modules/custom modules.
Folder structure – Creating a Folder
structure is again a simple but important
thing to follow. It helps to have a clear idea
of the components in the application. If you
have not correctly structured your folder,
then you can be in trouble for managing the
whole application. Irrespective of the size of
projects, you should always try to have the
habit of structuring your project.
7. Utilize Central State
Management
(Redux/Ngrx)
State management is manageable when you
are dealing with small or medium-sized
Angular applications, but as the size of the
application grows, the process becomes
quite tricky and hectic. There are so many
components having their local states, and
you need to have smooth communication
between these components. It is advisable
and considered one of the Angular best
practices to use central state management.
Now you might be wondering what central
state management is?
Here is the answer – Central State
Management means having all the states of
the components in one place, no need of
dividing it among various small
components unless there’s a requirement
for it. As the state of the entire application is
managed in one place, it makes the
communication between components a lot
easy.
No need to search the component tree,
as the state is managed in one place
It makes the transfer of data easy
The main issue of communication
between the component to component
is solved if your application has a
centralized state
It makes debugging less time taking
You have two great options for your
Angular application – Redux and Ngrx.
Advantages of Central State
Management –
The answer to which one you should prefer
altogether depends on your project’s
requirement, size of the application, and
technology stack. If you are dealing with
large applications where you have hundreds
of components to deal with, then redux is
the best for you. But, if you are dealing with
small or medium-sized applications, Redux
should be prevented. Considering redux for
such applications can indeed cause
performance issues and further complicates
the code.
So, this was all about the Angular
architecture, Angular code review checklist,
and Angular best practices to improve your
Angular code. I hope the purpose of landing
on this blog has served as per your
expectations. As I said before, you should
try to develop coding practices in any
technology or framework, which enhance
the performance, readability, and
understandability of the application. Best
applications are developed when
developers focus on how to code and what
not to code.
Take away
If you are looking for a helping hand to
improve your Angular application
performance, hire angular developer from
us today. Our Angular programmers are
well-versed in fulfilling all your custom
Angular code requirements. Get in touch
with our dedicated Angular developers to
make your existing Angular application
clean and performant.
Thank You

More Related Content

What's hot

Overview of the AngularJS framework
Overview of the AngularJS framework Overview of the AngularJS framework
Overview of the AngularJS framework
Yakov Fain
 
Angular 2 - The Next Framework
Angular 2 - The Next FrameworkAngular 2 - The Next Framework
Angular 2 - The Next Framework
Commit University
 
Introduction to Angular 2
Introduction to Angular 2Introduction to Angular 2
Introduction to Angular 2
Knoldus Inc.
 
Beyond AngularJS: Best practices and more
Beyond AngularJS: Best practices and moreBeyond AngularJS: Best practices and more
Beyond AngularJS: Best practices and more
Ari Lerner
 
The productive developer guide to Angular 2
The productive developer guide to Angular 2The productive developer guide to Angular 2
The productive developer guide to Angular 2
Maurice De Beijer [MVP]
 
Tech Webinar: Angular 2, Introduction to a new framework
Tech Webinar: Angular 2, Introduction to a new frameworkTech Webinar: Angular 2, Introduction to a new framework
Tech Webinar: Angular 2, Introduction to a new framework
Codemotion
 
Angular Dependency Injection
Angular Dependency InjectionAngular Dependency Injection
Angular Dependency Injection
Nir Kaufman
 
Introduction to angular 4
Introduction to angular 4Introduction to angular 4
Introduction to angular 4
Marwane El Azami
 
Migrating an application from Angular 1 to Angular 2
Migrating an application from Angular 1 to Angular 2 Migrating an application from Angular 1 to Angular 2
Migrating an application from Angular 1 to Angular 2
Ross Dederer
 
Angular from Scratch
Angular from ScratchAngular from Scratch
Angular from Scratch
Christian Lilley
 
Angular 2 - Better or worse
Angular 2 - Better or worseAngular 2 - Better or worse
Angular 2 - Better or worse
Vladimir Georgiev
 
Web components are the future of the web - Take advantage of new web technolo...
Web components are the future of the web - Take advantage of new web technolo...Web components are the future of the web - Take advantage of new web technolo...
Web components are the future of the web - Take advantage of new web technolo...
Marios Fakiolas
 
Introduction to Angular 2
Introduction to Angular 2Introduction to Angular 2
Introduction to Angular 2
Naveen Pete
 
AngularJs presentation
AngularJs presentation AngularJs presentation
AngularJs presentation
Phan Tuan
 
Flutter State Management Using GetX.pdf
Flutter State Management Using GetX.pdfFlutter State Management Using GetX.pdf
Flutter State Management Using GetX.pdf
Katy Slemon
 
Exploring Angular 2 - Episode 1
Exploring Angular 2 - Episode 1Exploring Angular 2 - Episode 1
Exploring Angular 2 - Episode 1
Ahmed Moawad
 
Angular2 Development for Java developers
Angular2 Development for Java developersAngular2 Development for Java developers
Angular2 Development for Java developers
Yakov Fain
 
Angular js 2
Angular js 2Angular js 2
Angular js 2
Ran Wahle
 
Up & running with ECMAScript6
Up & running with ECMAScript6Up & running with ECMAScript6
Up & running with ECMAScript6
Nir Kaufman
 
Angularjs
AngularjsAngularjs
Angularjs
Vincenzo Ferrari
 

What's hot (20)

Overview of the AngularJS framework
Overview of the AngularJS framework Overview of the AngularJS framework
Overview of the AngularJS framework
 
Angular 2 - The Next Framework
Angular 2 - The Next FrameworkAngular 2 - The Next Framework
Angular 2 - The Next Framework
 
Introduction to Angular 2
Introduction to Angular 2Introduction to Angular 2
Introduction to Angular 2
 
Beyond AngularJS: Best practices and more
Beyond AngularJS: Best practices and moreBeyond AngularJS: Best practices and more
Beyond AngularJS: Best practices and more
 
The productive developer guide to Angular 2
The productive developer guide to Angular 2The productive developer guide to Angular 2
The productive developer guide to Angular 2
 
Tech Webinar: Angular 2, Introduction to a new framework
Tech Webinar: Angular 2, Introduction to a new frameworkTech Webinar: Angular 2, Introduction to a new framework
Tech Webinar: Angular 2, Introduction to a new framework
 
Angular Dependency Injection
Angular Dependency InjectionAngular Dependency Injection
Angular Dependency Injection
 
Introduction to angular 4
Introduction to angular 4Introduction to angular 4
Introduction to angular 4
 
Migrating an application from Angular 1 to Angular 2
Migrating an application from Angular 1 to Angular 2 Migrating an application from Angular 1 to Angular 2
Migrating an application from Angular 1 to Angular 2
 
Angular from Scratch
Angular from ScratchAngular from Scratch
Angular from Scratch
 
Angular 2 - Better or worse
Angular 2 - Better or worseAngular 2 - Better or worse
Angular 2 - Better or worse
 
Web components are the future of the web - Take advantage of new web technolo...
Web components are the future of the web - Take advantage of new web technolo...Web components are the future of the web - Take advantage of new web technolo...
Web components are the future of the web - Take advantage of new web technolo...
 
Introduction to Angular 2
Introduction to Angular 2Introduction to Angular 2
Introduction to Angular 2
 
AngularJs presentation
AngularJs presentation AngularJs presentation
AngularJs presentation
 
Flutter State Management Using GetX.pdf
Flutter State Management Using GetX.pdfFlutter State Management Using GetX.pdf
Flutter State Management Using GetX.pdf
 
Exploring Angular 2 - Episode 1
Exploring Angular 2 - Episode 1Exploring Angular 2 - Episode 1
Exploring Angular 2 - Episode 1
 
Angular2 Development for Java developers
Angular2 Development for Java developersAngular2 Development for Java developers
Angular2 Development for Java developers
 
Angular js 2
Angular js 2Angular js 2
Angular js 2
 
Up & running with ECMAScript6
Up & running with ECMAScript6Up & running with ECMAScript6
Up & running with ECMAScript6
 
Angularjs
AngularjsAngularjs
Angularjs
 

Similar to Top 7 Angular Best Practices to Organize Your Angular App

Angular Best Practices To Build Clean and Performant Web Applications
Angular Best Practices To Build Clean and Performant Web ApplicationsAngular Best Practices To Build Clean and Performant Web Applications
Angular Best Practices To Build Clean and Performant Web Applications
Albiorix Technology
 
Angular kickstart slideshare
Angular kickstart   slideshareAngular kickstart   slideshare
Angular kickstart slideshare
SaleemMalik52
 
Angular Project Report
 Angular Project Report Angular Project Report
Angular Project Report
Kodexhub
 
ANGULAR JS LAB MANUAL(final) vtu2021 sch
ANGULAR JS LAB MANUAL(final) vtu2021 schANGULAR JS LAB MANUAL(final) vtu2021 sch
ANGULAR JS LAB MANUAL(final) vtu2021 sch
kannikadg
 
Best Practices to Ace ReactJS Web Development!
Best Practices to Ace ReactJS Web Development!Best Practices to Ace ReactJS Web Development!
Best Practices to Ace ReactJS Web Development!
Inexture Solutions
 
How Does Angular Work?
How Does Angular Work?How Does Angular Work?
How Does Angular Work?
Albiorix Technology
 
quantum_leap_angularjs_tools_redefining_development_in_2023.pptx
quantum_leap_angularjs_tools_redefining_development_in_2023.pptxquantum_leap_angularjs_tools_redefining_development_in_2023.pptx
quantum_leap_angularjs_tools_redefining_development_in_2023.pptx
sarah david
 
AngularJS in Production (CTO Forum)
AngularJS in Production (CTO Forum)AngularJS in Production (CTO Forum)
AngularJS in Production (CTO Forum)
Alex Ross
 
Training On Angular Js
Training On Angular JsTraining On Angular Js
Training On Angular Js
Mahima Radhakrishnan
 
Baparekraf Digital Talent Day: Monitoring dan Coaching Penerima Fasilitasi BD...
Baparekraf Digital Talent Day: Monitoring dan Coaching Penerima Fasilitasi BD...Baparekraf Digital Talent Day: Monitoring dan Coaching Penerima Fasilitasi BD...
Baparekraf Digital Talent Day: Monitoring dan Coaching Penerima Fasilitasi BD...
DicodingEvent
 
Industry-Standard Web Development Techniques for Angular
Industry-Standard Web Development Techniques for AngularIndustry-Standard Web Development Techniques for Angular
Industry-Standard Web Development Techniques for Angular
Jai Prakash Mishra
 
Angular js interview question answer for fresher
Angular js interview question answer for fresherAngular js interview question answer for fresher
Angular js interview question answer for fresher
Ravi Bhadauria
 
Angular
AngularAngular
Dive into Angular, part 5: Experience
Dive into Angular, part 5: ExperienceDive into Angular, part 5: Experience
Dive into Angular, part 5: Experience
Oleksii Prohonnyi
 
Basic iOS Training with SWIFT - Part 1
Basic iOS Training with SWIFT - Part 1Basic iOS Training with SWIFT - Part 1
Basic iOS Training with SWIFT - Part 1
Manoj Ellappan
 
Ng talk
Ng talkNg talk
Angular Interview Questions-PDF.pdf
Angular Interview Questions-PDF.pdfAngular Interview Questions-PDF.pdf
Angular Interview Questions-PDF.pdf
JohnLeo57
 
Intoduction to Angularjs
Intoduction to AngularjsIntoduction to Angularjs
Intoduction to Angularjs
Gaurav Agrawal
 
AngularJS in practice
AngularJS in practiceAngularJS in practice
AngularJS in practice
Eugene Fidelin
 
Flutter App Performance Optimization_ Tips and Techniques.pdf
Flutter App Performance Optimization_ Tips and Techniques.pdfFlutter App Performance Optimization_ Tips and Techniques.pdf
Flutter App Performance Optimization_ Tips and Techniques.pdf
DianApps Technologies
 

Similar to Top 7 Angular Best Practices to Organize Your Angular App (20)

Angular Best Practices To Build Clean and Performant Web Applications
Angular Best Practices To Build Clean and Performant Web ApplicationsAngular Best Practices To Build Clean and Performant Web Applications
Angular Best Practices To Build Clean and Performant Web Applications
 
Angular kickstart slideshare
Angular kickstart   slideshareAngular kickstart   slideshare
Angular kickstart slideshare
 
Angular Project Report
 Angular Project Report Angular Project Report
Angular Project Report
 
ANGULAR JS LAB MANUAL(final) vtu2021 sch
ANGULAR JS LAB MANUAL(final) vtu2021 schANGULAR JS LAB MANUAL(final) vtu2021 sch
ANGULAR JS LAB MANUAL(final) vtu2021 sch
 
Best Practices to Ace ReactJS Web Development!
Best Practices to Ace ReactJS Web Development!Best Practices to Ace ReactJS Web Development!
Best Practices to Ace ReactJS Web Development!
 
How Does Angular Work?
How Does Angular Work?How Does Angular Work?
How Does Angular Work?
 
quantum_leap_angularjs_tools_redefining_development_in_2023.pptx
quantum_leap_angularjs_tools_redefining_development_in_2023.pptxquantum_leap_angularjs_tools_redefining_development_in_2023.pptx
quantum_leap_angularjs_tools_redefining_development_in_2023.pptx
 
AngularJS in Production (CTO Forum)
AngularJS in Production (CTO Forum)AngularJS in Production (CTO Forum)
AngularJS in Production (CTO Forum)
 
Training On Angular Js
Training On Angular JsTraining On Angular Js
Training On Angular Js
 
Baparekraf Digital Talent Day: Monitoring dan Coaching Penerima Fasilitasi BD...
Baparekraf Digital Talent Day: Monitoring dan Coaching Penerima Fasilitasi BD...Baparekraf Digital Talent Day: Monitoring dan Coaching Penerima Fasilitasi BD...
Baparekraf Digital Talent Day: Monitoring dan Coaching Penerima Fasilitasi BD...
 
Industry-Standard Web Development Techniques for Angular
Industry-Standard Web Development Techniques for AngularIndustry-Standard Web Development Techniques for Angular
Industry-Standard Web Development Techniques for Angular
 
Angular js interview question answer for fresher
Angular js interview question answer for fresherAngular js interview question answer for fresher
Angular js interview question answer for fresher
 
Angular
AngularAngular
Angular
 
Dive into Angular, part 5: Experience
Dive into Angular, part 5: ExperienceDive into Angular, part 5: Experience
Dive into Angular, part 5: Experience
 
Basic iOS Training with SWIFT - Part 1
Basic iOS Training with SWIFT - Part 1Basic iOS Training with SWIFT - Part 1
Basic iOS Training with SWIFT - Part 1
 
Ng talk
Ng talkNg talk
Ng talk
 
Angular Interview Questions-PDF.pdf
Angular Interview Questions-PDF.pdfAngular Interview Questions-PDF.pdf
Angular Interview Questions-PDF.pdf
 
Intoduction to Angularjs
Intoduction to AngularjsIntoduction to Angularjs
Intoduction to Angularjs
 
AngularJS in practice
AngularJS in practiceAngularJS in practice
AngularJS in practice
 
Flutter App Performance Optimization_ Tips and Techniques.pdf
Flutter App Performance Optimization_ Tips and Techniques.pdfFlutter App Performance Optimization_ Tips and Techniques.pdf
Flutter App Performance Optimization_ Tips and Techniques.pdf
 

More from Katy Slemon

React Alternatives Frameworks- Lightweight Javascript Libraries.pdf
React Alternatives Frameworks- Lightweight Javascript Libraries.pdfReact Alternatives Frameworks- Lightweight Javascript Libraries.pdf
React Alternatives Frameworks- Lightweight Javascript Libraries.pdf
Katy Slemon
 
Data Science Use Cases in Retail & Healthcare Industries.pdf
Data Science Use Cases in Retail & Healthcare Industries.pdfData Science Use Cases in Retail & Healthcare Industries.pdf
Data Science Use Cases in Retail & Healthcare Industries.pdf
Katy Slemon
 
How Much Does It Cost To Hire Golang Developer.pdf
How Much Does It Cost To Hire Golang Developer.pdfHow Much Does It Cost To Hire Golang Developer.pdf
How Much Does It Cost To Hire Golang Developer.pdf
Katy Slemon
 
What’s New in Flutter 3.pdf
What’s New in Flutter 3.pdfWhat’s New in Flutter 3.pdf
What’s New in Flutter 3.pdf
Katy Slemon
 
Why Use Ruby On Rails.pdf
Why Use Ruby On Rails.pdfWhy Use Ruby On Rails.pdf
Why Use Ruby On Rails.pdf
Katy Slemon
 
How Much Does It Cost To Hire Full Stack Developer In 2022.pdf
How Much Does It Cost To Hire Full Stack Developer In 2022.pdfHow Much Does It Cost To Hire Full Stack Developer In 2022.pdf
How Much Does It Cost To Hire Full Stack Developer In 2022.pdf
Katy Slemon
 
How to Implement Middleware Pipeline in VueJS.pdf
How to Implement Middleware Pipeline in VueJS.pdfHow to Implement Middleware Pipeline in VueJS.pdf
How to Implement Middleware Pipeline in VueJS.pdf
Katy Slemon
 
How to Build Laravel Package Using Composer.pdf
How to Build Laravel Package Using Composer.pdfHow to Build Laravel Package Using Composer.pdf
How to Build Laravel Package Using Composer.pdf
Katy Slemon
 
Sure Shot Ways To Improve And Scale Your Node js Performance.pdf
Sure Shot Ways To Improve And Scale Your Node js Performance.pdfSure Shot Ways To Improve And Scale Your Node js Performance.pdf
Sure Shot Ways To Improve And Scale Your Node js Performance.pdf
Katy Slemon
 
How to Develop Slack Bot Using Golang.pdf
How to Develop Slack Bot Using Golang.pdfHow to Develop Slack Bot Using Golang.pdf
How to Develop Slack Bot Using Golang.pdf
Katy Slemon
 
IoT Based Battery Management System in Electric Vehicles.pdf
IoT Based Battery Management System in Electric Vehicles.pdfIoT Based Battery Management System in Electric Vehicles.pdf
IoT Based Battery Management System in Electric Vehicles.pdf
Katy Slemon
 
Understanding Flexbox Layout in React Native.pdf
Understanding Flexbox Layout in React Native.pdfUnderstanding Flexbox Layout in React Native.pdf
Understanding Flexbox Layout in React Native.pdf
Katy Slemon
 
The Ultimate Guide to Laravel Performance Optimization in 2022.pdf
The Ultimate Guide to Laravel Performance Optimization in 2022.pdfThe Ultimate Guide to Laravel Performance Optimization in 2022.pdf
The Ultimate Guide to Laravel Performance Optimization in 2022.pdf
Katy Slemon
 
New Features in iOS 15 and Swift 5.5.pdf
New Features in iOS 15 and Swift 5.5.pdfNew Features in iOS 15 and Swift 5.5.pdf
New Features in iOS 15 and Swift 5.5.pdf
Katy Slemon
 
How to Hire & Manage Dedicated Team For Your Next Product Development.pdf
How to Hire & Manage Dedicated Team For Your Next Product Development.pdfHow to Hire & Manage Dedicated Team For Your Next Product Development.pdf
How to Hire & Manage Dedicated Team For Your Next Product Development.pdf
Katy Slemon
 
Choose the Right Battery Management System for Lithium Ion Batteries.pdf
Choose the Right Battery Management System for Lithium Ion Batteries.pdfChoose the Right Battery Management System for Lithium Ion Batteries.pdf
Choose the Right Battery Management System for Lithium Ion Batteries.pdf
Katy Slemon
 
Flutter Performance Tuning Best Practices From the Pros.pdf
Flutter Performance Tuning Best Practices From the Pros.pdfFlutter Performance Tuning Best Practices From the Pros.pdf
Flutter Performance Tuning Best Practices From the Pros.pdf
Katy Slemon
 
Angular Universal How to Build Angular SEO Friendly App.pdf
Angular Universal How to Build Angular SEO Friendly App.pdfAngular Universal How to Build Angular SEO Friendly App.pdf
Angular Universal How to Build Angular SEO Friendly App.pdf
Katy Slemon
 
How to Set Up and Send Mails Using SendGrid in NodeJs App.pdf
How to Set Up and Send Mails Using SendGrid in NodeJs App.pdfHow to Set Up and Send Mails Using SendGrid in NodeJs App.pdf
How to Set Up and Send Mails Using SendGrid in NodeJs App.pdf
Katy Slemon
 
Ruby On Rails Performance Tuning Guide.pdf
Ruby On Rails Performance Tuning Guide.pdfRuby On Rails Performance Tuning Guide.pdf
Ruby On Rails Performance Tuning Guide.pdf
Katy Slemon
 

More from Katy Slemon (20)

React Alternatives Frameworks- Lightweight Javascript Libraries.pdf
React Alternatives Frameworks- Lightweight Javascript Libraries.pdfReact Alternatives Frameworks- Lightweight Javascript Libraries.pdf
React Alternatives Frameworks- Lightweight Javascript Libraries.pdf
 
Data Science Use Cases in Retail & Healthcare Industries.pdf
Data Science Use Cases in Retail & Healthcare Industries.pdfData Science Use Cases in Retail & Healthcare Industries.pdf
Data Science Use Cases in Retail & Healthcare Industries.pdf
 
How Much Does It Cost To Hire Golang Developer.pdf
How Much Does It Cost To Hire Golang Developer.pdfHow Much Does It Cost To Hire Golang Developer.pdf
How Much Does It Cost To Hire Golang Developer.pdf
 
What’s New in Flutter 3.pdf
What’s New in Flutter 3.pdfWhat’s New in Flutter 3.pdf
What’s New in Flutter 3.pdf
 
Why Use Ruby On Rails.pdf
Why Use Ruby On Rails.pdfWhy Use Ruby On Rails.pdf
Why Use Ruby On Rails.pdf
 
How Much Does It Cost To Hire Full Stack Developer In 2022.pdf
How Much Does It Cost To Hire Full Stack Developer In 2022.pdfHow Much Does It Cost To Hire Full Stack Developer In 2022.pdf
How Much Does It Cost To Hire Full Stack Developer In 2022.pdf
 
How to Implement Middleware Pipeline in VueJS.pdf
How to Implement Middleware Pipeline in VueJS.pdfHow to Implement Middleware Pipeline in VueJS.pdf
How to Implement Middleware Pipeline in VueJS.pdf
 
How to Build Laravel Package Using Composer.pdf
How to Build Laravel Package Using Composer.pdfHow to Build Laravel Package Using Composer.pdf
How to Build Laravel Package Using Composer.pdf
 
Sure Shot Ways To Improve And Scale Your Node js Performance.pdf
Sure Shot Ways To Improve And Scale Your Node js Performance.pdfSure Shot Ways To Improve And Scale Your Node js Performance.pdf
Sure Shot Ways To Improve And Scale Your Node js Performance.pdf
 
How to Develop Slack Bot Using Golang.pdf
How to Develop Slack Bot Using Golang.pdfHow to Develop Slack Bot Using Golang.pdf
How to Develop Slack Bot Using Golang.pdf
 
IoT Based Battery Management System in Electric Vehicles.pdf
IoT Based Battery Management System in Electric Vehicles.pdfIoT Based Battery Management System in Electric Vehicles.pdf
IoT Based Battery Management System in Electric Vehicles.pdf
 
Understanding Flexbox Layout in React Native.pdf
Understanding Flexbox Layout in React Native.pdfUnderstanding Flexbox Layout in React Native.pdf
Understanding Flexbox Layout in React Native.pdf
 
The Ultimate Guide to Laravel Performance Optimization in 2022.pdf
The Ultimate Guide to Laravel Performance Optimization in 2022.pdfThe Ultimate Guide to Laravel Performance Optimization in 2022.pdf
The Ultimate Guide to Laravel Performance Optimization in 2022.pdf
 
New Features in iOS 15 and Swift 5.5.pdf
New Features in iOS 15 and Swift 5.5.pdfNew Features in iOS 15 and Swift 5.5.pdf
New Features in iOS 15 and Swift 5.5.pdf
 
How to Hire & Manage Dedicated Team For Your Next Product Development.pdf
How to Hire & Manage Dedicated Team For Your Next Product Development.pdfHow to Hire & Manage Dedicated Team For Your Next Product Development.pdf
How to Hire & Manage Dedicated Team For Your Next Product Development.pdf
 
Choose the Right Battery Management System for Lithium Ion Batteries.pdf
Choose the Right Battery Management System for Lithium Ion Batteries.pdfChoose the Right Battery Management System for Lithium Ion Batteries.pdf
Choose the Right Battery Management System for Lithium Ion Batteries.pdf
 
Flutter Performance Tuning Best Practices From the Pros.pdf
Flutter Performance Tuning Best Practices From the Pros.pdfFlutter Performance Tuning Best Practices From the Pros.pdf
Flutter Performance Tuning Best Practices From the Pros.pdf
 
Angular Universal How to Build Angular SEO Friendly App.pdf
Angular Universal How to Build Angular SEO Friendly App.pdfAngular Universal How to Build Angular SEO Friendly App.pdf
Angular Universal How to Build Angular SEO Friendly App.pdf
 
How to Set Up and Send Mails Using SendGrid in NodeJs App.pdf
How to Set Up and Send Mails Using SendGrid in NodeJs App.pdfHow to Set Up and Send Mails Using SendGrid in NodeJs App.pdf
How to Set Up and Send Mails Using SendGrid in NodeJs App.pdf
 
Ruby On Rails Performance Tuning Guide.pdf
Ruby On Rails Performance Tuning Guide.pdfRuby On Rails Performance Tuning Guide.pdf
Ruby On Rails Performance Tuning Guide.pdf
 

Recently uploaded

みなさんこんにちはこれ何文字まで入るの?40文字以下不可とか本当に意味わからないけどこれ限界文字数書いてないからマジでやばい文字数いけるんじゃないの?えこ...
みなさんこんにちはこれ何文字まで入るの?40文字以下不可とか本当に意味わからないけどこれ限界文字数書いてないからマジでやばい文字数いけるんじゃないの?えこ...みなさんこんにちはこれ何文字まで入るの?40文字以下不可とか本当に意味わからないけどこれ限界文字数書いてないからマジでやばい文字数いけるんじゃないの?えこ...
みなさんこんにちはこれ何文字まで入るの?40文字以下不可とか本当に意味わからないけどこれ限界文字数書いてないからマジでやばい文字数いけるんじゃないの?えこ...
名前 です男
 
How to use Firebase Data Connect For Flutter
How to use Firebase Data Connect For FlutterHow to use Firebase Data Connect For Flutter
How to use Firebase Data Connect For Flutter
Daiki Mogmet Ito
 
Full-RAG: A modern architecture for hyper-personalization
Full-RAG: A modern architecture for hyper-personalizationFull-RAG: A modern architecture for hyper-personalization
Full-RAG: A modern architecture for hyper-personalization
Zilliz
 
TrustArc Webinar - 2024 Global Privacy Survey
TrustArc Webinar - 2024 Global Privacy SurveyTrustArc Webinar - 2024 Global Privacy Survey
TrustArc Webinar - 2024 Global Privacy Survey
TrustArc
 
PCI PIN Basics Webinar from the Controlcase Team
PCI PIN Basics Webinar from the Controlcase TeamPCI PIN Basics Webinar from the Controlcase Team
PCI PIN Basics Webinar from the Controlcase Team
ControlCase
 
Cosa hanno in comune un mattoncino Lego e la backdoor XZ?
Cosa hanno in comune un mattoncino Lego e la backdoor XZ?Cosa hanno in comune un mattoncino Lego e la backdoor XZ?
Cosa hanno in comune un mattoncino Lego e la backdoor XZ?
Speck&Tech
 
Mind map of terminologies used in context of Generative AI
Mind map of terminologies used in context of Generative AIMind map of terminologies used in context of Generative AI
Mind map of terminologies used in context of Generative AI
Kumud Singh
 
Unlock the Future of Search with MongoDB Atlas_ Vector Search Unleashed.pdf
Unlock the Future of Search with MongoDB Atlas_ Vector Search Unleashed.pdfUnlock the Future of Search with MongoDB Atlas_ Vector Search Unleashed.pdf
Unlock the Future of Search with MongoDB Atlas_ Vector Search Unleashed.pdf
Malak Abu Hammad
 
Securing your Kubernetes cluster_ a step-by-step guide to success !
Securing your Kubernetes cluster_ a step-by-step guide to success !Securing your Kubernetes cluster_ a step-by-step guide to success !
Securing your Kubernetes cluster_ a step-by-step guide to success !
KatiaHIMEUR1
 
Introducing Milvus Lite: Easy-to-Install, Easy-to-Use vector database for you...
Introducing Milvus Lite: Easy-to-Install, Easy-to-Use vector database for you...Introducing Milvus Lite: Easy-to-Install, Easy-to-Use vector database for you...
Introducing Milvus Lite: Easy-to-Install, Easy-to-Use vector database for you...
Zilliz
 
Introduction to CHERI technology - Cybersecurity
Introduction to CHERI technology - CybersecurityIntroduction to CHERI technology - Cybersecurity
Introduction to CHERI technology - Cybersecurity
mikeeftimakis1
 
Alt. GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using ...
Alt. GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using ...Alt. GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using ...
Alt. GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using ...
James Anderson
 
GraphSummit Singapore | Enhancing Changi Airport Group's Passenger Experience...
GraphSummit Singapore | Enhancing Changi Airport Group's Passenger Experience...GraphSummit Singapore | Enhancing Changi Airport Group's Passenger Experience...
GraphSummit Singapore | Enhancing Changi Airport Group's Passenger Experience...
Neo4j
 
Generative AI Deep Dive: Advancing from Proof of Concept to Production
Generative AI Deep Dive: Advancing from Proof of Concept to ProductionGenerative AI Deep Dive: Advancing from Proof of Concept to Production
Generative AI Deep Dive: Advancing from Proof of Concept to Production
Aggregage
 
Large Language Model (LLM) and it’s Geospatial Applications
Large Language Model (LLM) and it’s Geospatial ApplicationsLarge Language Model (LLM) and it’s Geospatial Applications
Large Language Model (LLM) and it’s Geospatial Applications
Rohit Gautam
 
“Building and Scaling AI Applications with the Nx AI Manager,” a Presentation...
“Building and Scaling AI Applications with the Nx AI Manager,” a Presentation...“Building and Scaling AI Applications with the Nx AI Manager,” a Presentation...
“Building and Scaling AI Applications with the Nx AI Manager,” a Presentation...
Edge AI and Vision Alliance
 
Goodbye Windows 11: Make Way for Nitrux Linux 3.5.0!
Goodbye Windows 11: Make Way for Nitrux Linux 3.5.0!Goodbye Windows 11: Make Way for Nitrux Linux 3.5.0!
Goodbye Windows 11: Make Way for Nitrux Linux 3.5.0!
SOFTTECHHUB
 
Essentials of Automations: The Art of Triggers and Actions in FME
Essentials of Automations: The Art of Triggers and Actions in FMEEssentials of Automations: The Art of Triggers and Actions in FME
Essentials of Automations: The Art of Triggers and Actions in FME
Safe Software
 
National Security Agency - NSA mobile device best practices
National Security Agency - NSA mobile device best practicesNational Security Agency - NSA mobile device best practices
National Security Agency - NSA mobile device best practices
Quotidiano Piemontese
 
Climate Impact of Software Testing at Nordic Testing Days
Climate Impact of Software Testing at Nordic Testing DaysClimate Impact of Software Testing at Nordic Testing Days
Climate Impact of Software Testing at Nordic Testing Days
Kari Kakkonen
 

Recently uploaded (20)

みなさんこんにちはこれ何文字まで入るの?40文字以下不可とか本当に意味わからないけどこれ限界文字数書いてないからマジでやばい文字数いけるんじゃないの?えこ...
みなさんこんにちはこれ何文字まで入るの?40文字以下不可とか本当に意味わからないけどこれ限界文字数書いてないからマジでやばい文字数いけるんじゃないの?えこ...みなさんこんにちはこれ何文字まで入るの?40文字以下不可とか本当に意味わからないけどこれ限界文字数書いてないからマジでやばい文字数いけるんじゃないの?えこ...
みなさんこんにちはこれ何文字まで入るの?40文字以下不可とか本当に意味わからないけどこれ限界文字数書いてないからマジでやばい文字数いけるんじゃないの?えこ...
 
How to use Firebase Data Connect For Flutter
How to use Firebase Data Connect For FlutterHow to use Firebase Data Connect For Flutter
How to use Firebase Data Connect For Flutter
 
Full-RAG: A modern architecture for hyper-personalization
Full-RAG: A modern architecture for hyper-personalizationFull-RAG: A modern architecture for hyper-personalization
Full-RAG: A modern architecture for hyper-personalization
 
TrustArc Webinar - 2024 Global Privacy Survey
TrustArc Webinar - 2024 Global Privacy SurveyTrustArc Webinar - 2024 Global Privacy Survey
TrustArc Webinar - 2024 Global Privacy Survey
 
PCI PIN Basics Webinar from the Controlcase Team
PCI PIN Basics Webinar from the Controlcase TeamPCI PIN Basics Webinar from the Controlcase Team
PCI PIN Basics Webinar from the Controlcase Team
 
Cosa hanno in comune un mattoncino Lego e la backdoor XZ?
Cosa hanno in comune un mattoncino Lego e la backdoor XZ?Cosa hanno in comune un mattoncino Lego e la backdoor XZ?
Cosa hanno in comune un mattoncino Lego e la backdoor XZ?
 
Mind map of terminologies used in context of Generative AI
Mind map of terminologies used in context of Generative AIMind map of terminologies used in context of Generative AI
Mind map of terminologies used in context of Generative AI
 
Unlock the Future of Search with MongoDB Atlas_ Vector Search Unleashed.pdf
Unlock the Future of Search with MongoDB Atlas_ Vector Search Unleashed.pdfUnlock the Future of Search with MongoDB Atlas_ Vector Search Unleashed.pdf
Unlock the Future of Search with MongoDB Atlas_ Vector Search Unleashed.pdf
 
Securing your Kubernetes cluster_ a step-by-step guide to success !
Securing your Kubernetes cluster_ a step-by-step guide to success !Securing your Kubernetes cluster_ a step-by-step guide to success !
Securing your Kubernetes cluster_ a step-by-step guide to success !
 
Introducing Milvus Lite: Easy-to-Install, Easy-to-Use vector database for you...
Introducing Milvus Lite: Easy-to-Install, Easy-to-Use vector database for you...Introducing Milvus Lite: Easy-to-Install, Easy-to-Use vector database for you...
Introducing Milvus Lite: Easy-to-Install, Easy-to-Use vector database for you...
 
Introduction to CHERI technology - Cybersecurity
Introduction to CHERI technology - CybersecurityIntroduction to CHERI technology - Cybersecurity
Introduction to CHERI technology - Cybersecurity
 
Alt. GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using ...
Alt. GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using ...Alt. GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using ...
Alt. GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using ...
 
GraphSummit Singapore | Enhancing Changi Airport Group's Passenger Experience...
GraphSummit Singapore | Enhancing Changi Airport Group's Passenger Experience...GraphSummit Singapore | Enhancing Changi Airport Group's Passenger Experience...
GraphSummit Singapore | Enhancing Changi Airport Group's Passenger Experience...
 
Generative AI Deep Dive: Advancing from Proof of Concept to Production
Generative AI Deep Dive: Advancing from Proof of Concept to ProductionGenerative AI Deep Dive: Advancing from Proof of Concept to Production
Generative AI Deep Dive: Advancing from Proof of Concept to Production
 
Large Language Model (LLM) and it’s Geospatial Applications
Large Language Model (LLM) and it’s Geospatial ApplicationsLarge Language Model (LLM) and it’s Geospatial Applications
Large Language Model (LLM) and it’s Geospatial Applications
 
“Building and Scaling AI Applications with the Nx AI Manager,” a Presentation...
“Building and Scaling AI Applications with the Nx AI Manager,” a Presentation...“Building and Scaling AI Applications with the Nx AI Manager,” a Presentation...
“Building and Scaling AI Applications with the Nx AI Manager,” a Presentation...
 
Goodbye Windows 11: Make Way for Nitrux Linux 3.5.0!
Goodbye Windows 11: Make Way for Nitrux Linux 3.5.0!Goodbye Windows 11: Make Way for Nitrux Linux 3.5.0!
Goodbye Windows 11: Make Way for Nitrux Linux 3.5.0!
 
Essentials of Automations: The Art of Triggers and Actions in FME
Essentials of Automations: The Art of Triggers and Actions in FMEEssentials of Automations: The Art of Triggers and Actions in FME
Essentials of Automations: The Art of Triggers and Actions in FME
 
National Security Agency - NSA mobile device best practices
National Security Agency - NSA mobile device best practicesNational Security Agency - NSA mobile device best practices
National Security Agency - NSA mobile device best practices
 
Climate Impact of Software Testing at Nordic Testing Days
Climate Impact of Software Testing at Nordic Testing DaysClimate Impact of Software Testing at Nordic Testing Days
Climate Impact of Software Testing at Nordic Testing Days
 

Top 7 Angular Best Practices to Organize Your Angular App

  • 1. SAARE JAHAAN SE ACHHA HINDSUTAN HUMARA Top 7 Angular Best Practices to Organize Your Angular App www.bacancytechnology.com
  • 2. Angular is a JavaScript framework widely used to make web apps, truly native apps and especially SPAs, efficiently. Angular has been designed in a way to overcome the limitations of other frameworks. With its dynamic features, you can create the best web apps with optimized speed and performance. The interactive tools offered by the Angular framework outdoes the features of other existing frameworks. Once you are developing your project using Angular, there’s no need to rely on other third-party libraries. Despite all the compelling features offered by Angular, if you overlook your coding practices for the Angular code, there are chances of facing performance issues.
  • 3. Maintaining your code is very important, not only for Angular but any other framework, because it directly affects the output, and you surely don’t want a clumsy web app. In this blog – we will discuss Angular best practices to improve your Angular app performance instantly. Get knowledgeable on how to refine your Angular code with a clean code checklist in Angular.
  • 4. Angular Best Practices to Improve Your Angular App Performance
  • 5. Whenever there’s a need to generate different templates for each item from the collection, we use the built-in Angular directive – ngFor. < ul > < li *ngFor="let item of items;">{{item.id}}< /li > < /ul > 1. Make Use of trackBy
  • 6. Now, let’s see what the problem with ngFor is. Suppose we need to change the iterative data due to some requirements. In that case, it will cause the problem as Angular doesn’t keep any record of the data being iterated and is unaware of the data being added or removed. For implementing this, Angular releases all the DOM elements related to the collection and adds them again. And we all know how expensive DOM manipulations can be when dealing with a massive collection of data. To avoid this costly manipulation, we can use trackBy. The use of trackBy is considered one of the optimum techniques to be followed. It gives a unique identifier to each item of the collections, and thus the render process of the whole DOM can be avoided.
  • 7. @Component({ selector: 'demo-app', template: ` < ul > < li *ngFor="let item of items;trackBy: trackByFunc">{{item.id}}< /li > < /ul > < button (click)="getAllItems()">Click to Refresh< /button > `, }) export class DemoApp { constructor() { this.items = [{id: 10}, {id: 20}, {id: 30}]; } getAllItems() { this.items = this.getAllItemsFromServer(); }
  • 8. getAllItemsFromServer() { return [{id: 10}, {id: 20}, {id: 30}, {id: 40}]; } trackByFunc(i, item) { return item.id; // or i } }
  • 9. It’s quite necessary but considered the best way to keep your component separate from your logic. I have seen many developers mixing the components and business logic; making it too complicated and messy to understand. And that’s why it is advisable to use the logic in a separate service. 2. Try Avoiding the Use of Logic in the Component
  • 10. Testing user interface and components is treated differently and is quite tricky compared to logic testing. And that’s why you should have separate services for component and business logic. Different services for business logic improves code quality and reusability. When you have your logic in your separate service, you can use that service in multiple components. And this way, the code coverage Angular decreases and eventually the build size too. You can reuse the code to write less code. Here are the reasons for avoiding the use of logic in the Angular coding standards –
  • 11. It indeed enhances the code review, readability, neatness of the code, and performance of the high-scale application. 3. Use of Lazy Loading The use of Lazy Loading can help you increase the performance and productivity of your application. Lazy Loading is a built- in feature that allows Javascript to load the component asynchronously whenever that particular route hits. it divides the entire app into various bundles to manage its speed. So, all the components related to the active route will be loaded. Lazy Loading in Angular is used only at the start of the application. Once the application begins and the user starts navigating, it will load immediately.
  • 12. (1) In your app routing file, use loadchildren rather than a component. const routing: Routes = [ { path: 'items', loadChildren: () => import('./data/data.module'). then(d => d.DemoModule) } ]; Visit Angular documentation and explore more regarding its features. Here is the Primary Implementation in Your Angular Modules Best Practices-
  • 13. const routing: Routes = [ { path: '', component: DemoComponent } ]; Now, add the route of that particular component in the routing module for the Lazy Loaded module.
  • 14. Observable Memory Leaks are commonly noticed in almost all frameworks and libraries. Angular also has the same issue. Angular Observables mainly streamlines whole data, but memory leaks can be caused if you are not attentive enough. Memory Leaks are one of the severe and harmful problems attacking the application’s security. Here are some suggestions to secure your application – – Use of async pipe You can use an async pipe and promise to prevent memory leaks. You should try your best to avoid subscribing to observables and then binding them with the components. 4. Prevent Memory Leaks
  • 15. So, the conclusion is if the observable technique is not entirely done, the chances of memory leaks are likely to occur. – Use of take(1) take(1) is an operator. It takes the value and allows for not subscribing whenever a new value is diagnosed. It takes care that you receive data only once. It prevents leaking of memory in an efficient way. info$.pipe(take(1)).subscribe((response)=>co nsole.log(response)) – Use of takeUntil takeUntil is also an operator. It allows monitoring the Observables and get rid of the subscriptions once the value is emitted by Observables. We can conclude that it secures the Observables from getting leaked.
  • 16. export class DemoApp implements OnInit, OnDestroy { constructor(private route: ActiveRoute, private http: Http) { } ngOnInit() { this.route.params .takeUntil(destroyedComp(this)) .subscribe(param => { // write code here... }); this.http.get("/loading") .takeUntil(destroyedComp(this)) .subscribe(res => { // write code here... }); } ngOnDestroy() { // empty } }
  • 17. At the time of Angular code review, I have observed many developers using ‘any’ as variable types, which is not one of the Angular best practices. The thing with ‘any’ is that Angular will assume the variable’s type based on that particular variable’s value. So, you have to be doubly sure when you use ‘any’ to declare a variable, or else it could cause some small bugs that can be hard to debug. Let’s take an example here – If you have this code. 5. Declaring Variable Types Rather Than Using any
  • 18. let a = 10; let b = 'xyz'; let c = a + b; console.log(`Value of c: ${z}` // Output Value of c: 10xyz In the above code, the output will be as expected. But, if you have code like this – let p: number = 10; let q: number = 'xyz'; let r: number = a + b; // compile error: Type '"xyz"' is not assignable to type 'number'. let s: number
  • 19. You might not get the expected value all the time. To avoid that, you can use number instead of any. 6. Angular Coding Practices and Folder Structure Most of the developers tend to overlook the importance of standard coding practices. But, very few realize that following the code styles can help their fellow developers for code review quickly and adequately. It is not just for Angular; you should try to follow the coding practices in any programming language you are using. It increases the understandability, readability, simplicity, and adaptability of your project.
  • 20. Here are some coding standards you can keep in your mind – Every single file should have code lines within 400. Every single function should have the code lines within 75. For different slider components, use a custom prefix. Utilize const if the values are constant throughout the file. Names of functions should be meaningful and in the lower camel case. Always have a habit of leaving an empty line between all the imports and modules; once you are done importing all the third-party applications, leave a blank line and then start with modules/custom modules.
  • 21. Folder structure – Creating a Folder structure is again a simple but important thing to follow. It helps to have a clear idea of the components in the application. If you have not correctly structured your folder, then you can be in trouble for managing the whole application. Irrespective of the size of projects, you should always try to have the habit of structuring your project. 7. Utilize Central State Management (Redux/Ngrx)
  • 22. State management is manageable when you are dealing with small or medium-sized Angular applications, but as the size of the application grows, the process becomes quite tricky and hectic. There are so many components having their local states, and you need to have smooth communication between these components. It is advisable and considered one of the Angular best practices to use central state management. Now you might be wondering what central state management is? Here is the answer – Central State Management means having all the states of the components in one place, no need of dividing it among various small components unless there’s a requirement for it. As the state of the entire application is managed in one place, it makes the communication between components a lot easy.
  • 23. No need to search the component tree, as the state is managed in one place It makes the transfer of data easy The main issue of communication between the component to component is solved if your application has a centralized state It makes debugging less time taking You have two great options for your Angular application – Redux and Ngrx. Advantages of Central State Management –
  • 24. The answer to which one you should prefer altogether depends on your project’s requirement, size of the application, and technology stack. If you are dealing with large applications where you have hundreds of components to deal with, then redux is the best for you. But, if you are dealing with small or medium-sized applications, Redux should be prevented. Considering redux for such applications can indeed cause performance issues and further complicates the code.
  • 25. So, this was all about the Angular architecture, Angular code review checklist, and Angular best practices to improve your Angular code. I hope the purpose of landing on this blog has served as per your expectations. As I said before, you should try to develop coding practices in any technology or framework, which enhance the performance, readability, and understandability of the application. Best applications are developed when developers focus on how to code and what not to code. Take away
  • 26. If you are looking for a helping hand to improve your Angular application performance, hire angular developer from us today. Our Angular programmers are well-versed in fulfilling all your custom Angular code requirements. Get in touch with our dedicated Angular developers to make your existing Angular application clean and performant.