DEV Community

Cover image for Standalone Components, directives and pipes in Angular
devashishSarmah
devashishSarmah

Posted on • Edited on

1

Standalone Components, directives and pipes in Angular

As of you who works with Angular knows that the Angular framework is revolving around the concept of ngModule.

NgModule is currently one of the core concepts in Angular. Developers new to Angular need to learn about this concept before creating even a simple application.

Given this central role of NgModule in Angular it is hard to reason about components, directives and pipes in isolation.

NgModules are the smallest reusable building blocks in Angular, not components.

The current scenario

In today's Angular, whenever we create a component, we need to declare it in a ngModule. Irrespective of its use in other modules.

@Component({...})
export class UserViewComponent {
  constructor(readonly service: UserViewService) {}
}

@NgModule({
 declarations: [UserViewComponent],
  imports: [/* dependencies here */],
  providers: [{provide: UserViewService, useClass: BackendUserViewService}],
})
export class UserViewModule {}
Enter fullscreen mode Exit fullscreen mode

What are the things a standalone component will offer?

A standalone component will basically offer us to create components without creating a ngModule.

It will look something like this.

import {Component} from '@angular/core';

@Component({
  standalone: true,  
  template: `I'm a standalone component!`
})
export class HelloStandaloneComponent {}
Enter fullscreen mode Exit fullscreen mode

There are a bunch of exciting ideas opens up with this concept coming into the picture

When will this feature get released?

Recently the RFC for this feature has been completed
Link

So, We can expect it to get released soon

You can also checkout this prototype link to get an early look of how it's going to be.

This feature is surely going to be a game changer

Thanks for Reading!

Thanks for reading, I hope you enjoyed it!

Sentry blog image

How to reduce TTFB

In the past few years in the web dev world, we’ve seen a significant push towards rendering our websites on the server. Doing so is better for SEO and performs better on low-powered devices, but one thing we had to sacrifice is TTFB.

In this article, we’ll see how we can identify what makes our TTFB high so we can fix it.

Read more

Top comments (0)

A Workflow Copilot. Tailored to You.

Pieces.app image

Our desktop app, with its intelligent copilot, streamlines coding by generating snippets, extracting code from screenshots, and accelerating problem-solving.

Read the docs

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay