Sitemap
Usama Wahid

Usama Wahid

I’m a Full-stack developer with extensive experience with a variety of front-end and back-end languages, frameworks, and databases with the best techniques.

Angular in a Nutshell

3 min readDec 21, 2021
Angular

Angular is a TypeScript based framework for building user interfaces. It was developed at Google and released in 2016. As the sequel to Angular JS as an Angular developer, you hit the ground running with its extremely powerful CLI tool. When you generate your initial application, it comes pre-configured with routing, a testing framework, and your favorite style preprocessor.

Angular project

In addition, the magic ng add command can turn your app into a progressive web app, add server-side rendering Firebase support and do a whole bunch of other cool stuff. But at its core, Angular is just a component-based UI library, I can create a component with the CLI.

Press enter or click to view image in full size
Component Decorator

And if we go into its TypeScript file, you’ll notice the component decorator, which makes this TypeScript Class A component, any properties on this class are considered a reactive state. And when their values change, that component will rerender the UI. For example, we can bind the property to HTML using double braces in the template. From there, we can add a button that increments this value. Every time it’s clicked, we add the event name on the left side in parentheses, then an expression on the right side. In this case, it points to a method in our class. Each time the button is clicked, it calls the method which changes the state and re-render the UI. Angular also has a variety of directives for building complex templates use ngIf to handle conditional logic,

Press enter or click to view image in full size
ngIf

or if you have an iterable value use ngFor to loop over it.

ngFor

But where Angular really excels is handling complexity. And one of its primary tools for doing so is called dependency injection. When your app grows to hundreds of components, you’ll likely need a way to share data and functionality between them.

Press enter or click to view image in full size
Component

We can take our component logic here and extract it into a service that can be treated as a global singleton throughout the application. Now any component that wants to use this state or logic can simply add this class to its constructor.

Service

The end result is a simple and reliable way to compose complex applications. As a developer, you can always count on a consistent experience between projects and minimal decision fatigue.

Get Usama Wahid’s stories in your inbox

Join Medium for free to get updates from this writer.

Please Follow for more

Thanks for Reading.

--

--

Usama Wahid
Usama Wahid

Written by Usama Wahid

I’m a Full-stack developer with extensive experience with a variety of front-end and back-end languages, frameworks, and databases with the best techniques.