Things that helps to improve your Angular Code

In this blog, we will see how to reduce the code, follow the conventions, and stick to typescript code.

Let’s get started 🙂 

Follow the Angular Conventions

Working on any programming language, we first study and use syntax, but we should also follow the conventions that angular uses despite syntax.

For example:

File Name Conventions 

Structure of angular file must be


If we create a component then : user.component.ts

If we create a service then: user.service.ts
If its a module then: user.module.ts


The best way to simplify your code is to divide the code that is modularized.

Modules are nothing but the features that we want to build in our application.

All these modules are combined in the app module. So in technical terms, it is also called Lazy Loading. In Lazy loading, the module is loaded whenever its route is called.

Another advantage of modularization is we can reuse the module in different applications if we keep it completely separate.

A shared module is different from feature implementation, but functionality commonly used in all modules will fit in the shared module.

The shared module is called in the modules file where we want to use it. Pipes is a good example of a shared module.


Services are something where you can add your code which will be shared throughout the project. 

Most of the time, Business logic, Common functions like HTTP API calls are written in services.

Most services are created according to modules, so each service has its own set of functions according to features.

Avoid Promises and Use Observables

I really like the await operator for promises, but now we need to stick with the framework. HTTP module uses observables to handle AJAX requests and responses. The Router and Forms modules use observables to listen for and respond to user-input events. This will also make our calls asynchronous and we will be able to avoid the promises.

Lets see an example:

Users : USER = [];
ngOnInit() {
this.userService.getList().subscribe(user => {
Most of us forget to unsubscribe from the observable, this can lead to an unexpected changes in the application.
You can unsubscribe from observables in ngOnDestroy() function.

Users : USER = [];
ngOnInit() {
    this.userSubscription = this.userService.getList().subscribe(user => {





We can avoid such mistakes easily by using async pipes. This pipe automatically unsubscribes from observables whenever the component gets destroyed.

user$ : User = [];
ngOnInit() {
    this.user$ = this.http.get('');

Use the variable for template binding using the async pipe 

<p>{{user$ | async}}</p>

Now, the code looks simpler and cleaner.

StyleSheet Management

One of the big tasks is to manage CSS. We always try to reduce the CSS but somehow, it gets repeated. For such reasons, we can use the advantages provided by the SCSS. It gives the ability to declare the style variables to manage this by using common.SCSS and variable.SCSS structures.

This is one of the best practices to keep our CSS compact and simple.

Create one file called a variable.SCSS, which includes all common colors, sizes and fonts you will use throughout the project.

Let see an example:

$error: #FF0000;
$button_color : #6deace;
$text_color :  #96d7e4;

$text-font-size : 14px;

We just import this file in a component CSS file and then we can use variables.

@import 'styles/variables.scss';


     color: $error;

 background-color : $button_color;

This is an example for colors, but you can create variables for any of the styles.

Mostly variable.scss is used for changing the theme of the application.

Lets move to common.scss.This file includes the common scss classes which can be used through the project.

For example
color: $text_color;
font-size :$text-font-size;
padding: 10px;
font-family : sans-serif;
<div *ngFor=”let user of users”>
<p class=”user-list-view”>{{user}}</p>
These are some of the recommendations to keep the code simple and clean. I hope you liked it.


Full-stack Developer

Devashree is a Full-stack developer with around 2 years of experience. Her expertise is in the angular framework and has worked on angular 4+ versions. She has also worked on nodeJS and Ionic framework version 3.

Get in touch for a detailed discussion.

Hear From Our 100+ Customers

Mindbowser helped us build an awesome iOS app to bring balance to people’s lives.


We had very close go live timeline and MindBowser team got us live a month before.

Shaz Khan
CEO, BuyNow WorldWide

They were a very responsive team! Extremely easy to communicate and work with!

Kristen M.
Founder & CEO, TotTech

We’ve had very little-to-no hiccups at all—it’s been a really pleasurable experience.

Chacko Thomas
Co-Founder, TEAM8s

Mindbowser is one of the reasons that our app is successful. These guys have been a great team.

Dave Dubier
Founder & CEO, MangoMirror

Mindbowser was very helpful with explaining the development process and started quickly on the project.

Hieu Le
Executive Director of Product Development, Innovation Lab

The greatest benefit we got from Mindbowser is the expertise. Their team has developed apps in all different industries with all types of social proofs.

Alex Gobel
Co-Founder, Vesica

Mindbowser is professional, efficient and thorough. 

MacKenzie R
Consultant at XPRIZE

Very committed, they create beautiful apps and are very benevolent. They have brilliant Ideas.

Laurie Mastrogiani
Founder, S.T.A.R.S of Wellness

MindBowser was great; they listened to us a lot and helped us hone in on the actual idea of the app.” “They had put together fantastic wireframes for us.

Bennet Gillogly
Co-Founder, Flat Earth

They're very tech-savvy, yet humble.

Uma Nidmarty
CEO, GS Advisorate, Inc.

Ayush was responsive and paired me with the best team member possible, to complete my complex vision and project. Could not be happier.

Katie Taylor
Founder, Child Life On Call

As a founder of a budding start-up, it has been a great experience working with Mindbower Inc under Ayush's leadership for our online digital platform design and development activity.

Radhika Kotwal
Founder of Courtyardly

The team from Mindbowser stayed on task, asked the right questions, and completed the required tasks in a timely fashion! Strong work team!

Michael Wright
Chief Executive Officer, SDOH2Health LLC

They are focused, patient and; they are innovative. Please give them a shot if you are looking for someone to partner with, you can go along with Mindbowser.

David Cain
CEO, thirty2give

We are a small non-profit on a budget and they were able to deliver their work at our prescribed budgets. Their team always met their objectives and I'm very happy with the end result. Thank you, Mindbowser team!!

Bart Mendel
Founder, Mindworks