Angular would be better for developing the client-side of the web application.

Wathsala Rasanjalee Ganewatta
7 min readJun 1, 2021

What is Angular?

Angular is a TypeScript-based open-source web application framework led by the Angular Team at Google and by a community of individuals and corporations. Angular is a complete rewrite from the same team that built AngularJS.

Angular helps build interactive and dynamic single-page applications. Angular applications are built using the typeScript language. TypeScript ensures higher security as it supports types (primitives, interfaces, etc.).It helps catch and eliminate errors early when writing the code or performing maintenance tasks. We can directly debug TypeScript code in the browser or an editor if we have proper map files created during build time.

This language ensures improved,

  • navigation
  • refactoring
  • autocompletion services.

We can even opt out of its inbuilt features when needed.

Why We use Angular instead of other Frameworks?

Angular has some features that would help to implement a better application,

  • Templating → Designers can use HTML as the template language. And also HTML syntax can easily convey the components of the application. HTML is a declarative and intuitive language.
  • Two-way binding → Two-way binding gives components in your application a way to share data.Use two-way binding to listen for events and update values simultaneously between parent and child components. Two do the two-way binding need to have the knowledge of Property binding, Event binding, Inputs, and Outputs.

property binding

property binding do with different ways.To bind to an element’s property, enclose it in square brackets, ([]), which identifies the property as a target property.

For Example:
app.component.html

<img [src]="sourceUrl"> // display the image using property binding
<img src = "{{sourceUrl}}" // display image using iterpolation
<p> {{imageName}}</p> // display the content of the imageName

To setting up data to the sourceUrl using typeScript file.

app.component.ts

sourceUrl = "../assests/image.jpg"
imageName= "paragaraph image"

Event Binding

Event binding allows you to listen for and respond to user actions such as keystrokes, mouse movements, clicks, and touches. Angular have already defined events like click. And also can create custom event using EventEmitter.

Input Output

@Input() decorate use to share data from parent component to child componentent.

child.component.ts

@Input() profile:Customer

In child.component.html file

<div class="popover-body"><h6 *ngIf="customer || worker">{{profile.firstName}} {{profile.lastName}}</h6><h6 *ngIf="agent">{{profile.name}} </h6><p>{{profile.username}}</p><app-rate-bar [givenRate] = "profile.rate" [display]=true></app-rate-bar><hr><p (click)="toProfile()" class="profile">Profile</p><p (click)="giveFeedback()" class="profile">Feedback</p><p (click)="signOut()" class="profile">Sign Out</p></div>

parent.component.html

<app-profile *ngIf="show" [profile] = 'profile' ></app-profile>

@Outout() decorator use share data from child component to parent component. we can set value using emit()

child.component.ts

@Output() showProfile:EventEmitter<boolean> =new EventEmitter<boolean>();constructor(){}disposeProfile(){this.showProfile.emit(false)}

parent.component.html

<app-profile *ngIf="show" (showProfile)='toggleProfile($event)' ></app-profile>

parent.component.ts

toggleProfile(event){this.show = event.value}
  • Modularization → Angular apps are modular and their own modularity system called NgModules. NgModules are containers for a cohesive block of code dedicated to an application domain, a workflow, or a closely related set of capabilities
  • RESTful API handling → Most front-end applications need to communicate with a server over the HTTP protocol, in order to download or upload data and access other back-end services. Angular provides a client HTTP API for Angular applications, the HttpClient service class in @angular/common/http.
  • Dependency injection → Dependencies are services or objects that a class needs to perform its function. Angular’s Dependency Injection framework provides dependencies to a class upon instantiation. Using this Dependency injection can increase the flexibility and the modularity of the application. in this use @Injectable decorator of the class.
  • AJAX handling → Ajax stands for Asynchronous JavaScript and XML. It is used to request data from the server without full-page refresh, and use the result, which was originally XML, to re-render a part of the page.

Angular also has features and benefits

Angular has MVC Pattern MVVM(Model-View-ViewModel)

MVC stands for Model-View-Controller.

  1. Model — It is responsible for managing application data. It responds to the requests from view and to the instructions from the controller to update itself.
  2. View — It is responsible for displaying all data or only a portion of data to the users. It also specifies the data in a particular format triggered by the controller’s decision to present the data. They are script-based template systems such as JSP, ASP, PHP and very easy to integrate with AJAX technology.
  3. Controller — It is responsible to control the relation between models and views. It responds to user input and performs interactions on the data model objects. The controller receives input, validates it, and then performs business operations that modify the state of the data model.

The MVVM model supports two-way data binding between View and ViewModel.

Consistency of the code

The angular framework is based on components, which begin in the same style. For instance, each component places the code in a component class or defines a @Component decorator (metadata). These components are small interface elements independent from each other, and thus, offer you several benefits,

  • Being independent of each other, the components make unit testing much easier. → we can separately do the unit testing because of the independent component.
  • Reusability → There are two main ways to create reusable components in Angular:

1. Pass inputs to the component, passing the necessary data to the component used for rendering and configuring the component. This normally involves iterating over the provided data and follow a convention for how to render the data.

2.Use transclusion/content projection to pass a template to the reusable component and show the templateRefs inside the component using the ngTemplateOutlet directive or ng-content.

There is a subtle difference between using templateRef vs. using ng-content because of how Angular’s lifecycle management works.

The ngOnChanges() method is your first opportunity to access those properties. Angular calls ngOnChanges() before ngOnInit(), but also many times after that. It only calls ngOnInit() once.

For Example If we develop a web application. Then there would be same header parts in the every page we route. So that kind of situation we can create a sepparete header component and that can use in every where what we want to use.
  • Improved Readability → If we use the separate components to separate functions that would be easy to read the code. If anyone new to the project, that new one can easily grab what is done in that project.
  • Ease of Maintenance → Using this modularize way that can easy to maintain the project.

For what projects fit Angular?

  1. Enterprise web apps

TypeScript has all the features needed to develop large-scale projects. TypeScript is equipped with autocompletion, advanced refactoring, and navigation features.

2. Apps with dynamic content

Since the primary purpose of Angular was to create single-page web applications, it has a wide range of tools for SPA development. It’s an ideal technology for websites where the content should change dynamically based on user behavior and preferences. Dependency injections ensure that in case one component is changed, other components related to it will be changed automatically.

3. Progressive web apps (PWAs)

The Angular team foresees the upcoming popularity of PWAs and is working on facilitating the process of creating PWAs.

For what project Angular not Suite?

  • Lightweight websites with static content

Angular is ideal for websites with dynamic content, but it’s insufficient when building small pages with static content. Implementing Angular in this case only increases the overall size of the project and hence increases the load time significantly. That’s why not suitable for landing pages and websites with static content.

  • Short-term projects

Angular isn’t a good solution for short-term projects or startups with limited resources. It’s also not a good idea for projects with few developers, since the front-end framework’s complexity may be hard to overcome.

  • Apps with a microservice design approach

Angular isn’t suitable for applications with a microservice architecture on the frontend.

References:

I recommend to all the developers to learn about Angular and develop using angular. I sure that would be a great experience in your life.

--

--