• Technologies
  • AI Tips and Tricks
  • Frontend
  • Backend
  • Server
  • Contact
  • About
Sunday, February 1, 2026
Adnan Halilovic Blog
  • Technologies
    • All
    • Angular
    • Git
    • JavaScript
    • ReactJS
    Solving the Diamond Problem with Angular Signals

    Solving the Diamond Problem with Angular Signals

    Angular 21: Why Native [class] is 2x Faster than ngClass!

    Angular 21: Why Native [class] is 2x Faster than ngClass!

    VS Code Setup for Angular Developers Featured Image

    Best VS Code Setup for Angular Development

    Mastering DevTools: Supercharge Your Workflow with Code Snippets!

    Mastering DevTools: Supercharge Your Workflow with Code Snippets!

    Quokka.js and Wallaby.js Giveaway

    Quokka.js and Wallaby.js Giveaway

    How to Work on Different Git Branches at the Same Time?

    How to Work on Different Git Branches at the Same Time?

    Lazyload Standalone Components in Angular

    Lazyloading Standalone Components in Angular

    Standalone Components Angular

    How to Create Standalone Components in Angular

    Private Routes in React Router V6

    Protecting Routes in React JS

  • AI Tips and Tricks
  • Frontend
  • Backend
  • Server
  • Contact
  • About
No Result
View All Result
  • Technologies
    • All
    • Angular
    • Git
    • JavaScript
    • ReactJS
    Solving the Diamond Problem with Angular Signals

    Solving the Diamond Problem with Angular Signals

    Angular 21: Why Native [class] is 2x Faster than ngClass!

    Angular 21: Why Native [class] is 2x Faster than ngClass!

    VS Code Setup for Angular Developers Featured Image

    Best VS Code Setup for Angular Development

    Mastering DevTools: Supercharge Your Workflow with Code Snippets!

    Mastering DevTools: Supercharge Your Workflow with Code Snippets!

    Quokka.js and Wallaby.js Giveaway

    Quokka.js and Wallaby.js Giveaway

    How to Work on Different Git Branches at the Same Time?

    How to Work on Different Git Branches at the Same Time?

    Lazyload Standalone Components in Angular

    Lazyloading Standalone Components in Angular

    Standalone Components Angular

    How to Create Standalone Components in Angular

    Private Routes in React Router V6

    Protecting Routes in React JS

  • AI Tips and Tricks
  • Frontend
  • Backend
  • Server
  • Contact
  • About
No Result
View All Result
Adnan Halilovic Blog
No Result
View All Result

How to Create Standalone Components in Angular

Adnan Halilovic by Adnan Halilovic
September 10, 2022
in Angular, Frontend, Technologies
0
0
SHARES
208
VIEWS
Share on FacebookShare on Twitter
ADVERTISEMENT

With the introduction of standalone components in Angular versions 14 and later, building Angular applications is simplified.


As the feature is still in developer preview, we will test it to determine its functionality, but be aware that it may undergo changes before it becomes stable.

What has changed?

Creating a standalone component is surprisingly simple. The only thing we must do is add the --standalone flag when creating the component via the CLI. So in the next steps, we are going to see it in action.


Generating a component

With the following command, we are creating a new component named standalone. (The name of the component could be anything else, but I just used the name standalone because of the simplicity).

ng g c standalone --standalone

After executing this command, the generated component should appear as follows.

import { Component, OnInit } from '@angular/core';
import { CommonModule } from '@angular/common';

@Component({
  selector: 'app-standalone',
  standalone: true,
  imports: [CommonModule],
  templateUrl: './standalone.component.html',
  styleUrls: ['./standalone.component.scss'],
})
export class StandaloneComponent implements OnInit {
  constructor() {}

  ngOnInit(): void {}
}

New properties?

As you could notice, in the code above, we have two new properties in the @component decorator.

  • standalone – A boolean value that tells the Angular’s standalone API that this component is actually standalone.
  • imports – An array that accepts modules, pipes, directives, and components (The components have to be standalone as well, to be able to import them).

Using components in modules and components that are not standalone

As the standalone component is not going to be imported into any module while generating it, we have to do it manually if we are looking to import the component into a non-standalone / standard component.

ADVERTISEMENT

So, to achieve this, we are going to, in this case, app.module.ts and to add the standalone component into imports array, not into the declarations as is the case with standard components.

So our app module should look like this:

import { NgModule } from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';

import { AppRoutingModule } from './app-routing.module';
import { AppComponent } from './app.component';
import { StandaloneComponent } from './standalone/standalone.component';

@NgModule({
  declarations: [AppComponent],
  imports: [
    BrowserModule,
    AppRoutingModule,
    StandaloneComponent,
  ],
  providers: [],
  bootstrap: [AppComponent],
})
export class AppModule {}

After importing the component we are able to use it in our app.component.ts.

ADVERTISEMENT

Importing standalone components into standalone components

This step is really easy. Let’s say that we have created a new standalone component named button and we have to import it into the standalone component that we generated earlier.

To achieve this, we would have just to add that component to our imports located in the standalone component’s decorator, as in the following example.

import { Component, OnInit } from '@angular/core';
import { CommonModule } from '@angular/common';
import { ButtonComponent } from './components/button/button.component';

@Component({
  selector: 'app-standalone',
  standalone: true,
  imports: [CommonModule, ButtonComponent],
  templateUrl: './standalone.component.html',
  styleUrls: ['./standalone.component.scss'],
})
export class StandaloneComponent implements OnInit {
  constructor() {}

  ngOnInit(): void {}
}

Now, we are able to use the button component in our standalone component and do whatever we want.


Conclusion

Standalone components are really flexible and easy to use. We can look at them now as real components, or as shared components / shared apps/libs.. etc., as we are able if structured properly, just to copy the component from one to another project and use it out of the box.

Here is also a link to a repository that I created for this purpose: https://github.com/adnan-halilovic/standalone-components-angular

You can watch the tutorial video on this topic.

Thank you for reading the article.

For more content like this, follow me on youtube and other social networks that you can find on the website.

Source: YouTube
Via: Adnan Halilovic's YouTube Channel
Tags: Angularstandalone components
ADVERTISEMENT
Previous Post

Protecting Routes in React JS

Next Post

Lazyloading Standalone Components in Angular

Related Posts

Solving the Diamond Problem with Angular Signals
Angular

Solving the Diamond Problem with Angular Signals

January 29, 2026
Angular 21: Why Native [class] is 2x Faster than ngClass!
Angular

Angular 21: Why Native [class] is 2x Faster than ngClass!

January 20, 2026
Windsurf SWE-1 Featured Image
AI Tips and Tricks

Windsurf SWE-1: A Groundbreaking Frontier Model Family for Engineers

May 20, 2025
AI Coding Competition Featured Image
AI Tips and Tricks

LM Arena: The Ultimate Playground for Web Developers to Benchmark AI Language Models

May 20, 2025
VS Code Setup for Angular Developers Featured Image
Angular

Best VS Code Setup for Angular Development

October 13, 2024
My Top 5 Uncommon VS Code Extensions for 2024!
Frontend

My Top 5 Uncommon VS Code Extensions for 2024!

January 27, 2024
Next Post
Lazyload Standalone Components in Angular

Lazyloading Standalone Components in Angular

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Latest posts

Solving the Diamond Problem with Angular Signals
Angular

Solving the Diamond Problem with Angular Signals

by Adnan Halilovic
January 29, 2026
0

So, imagine you are in a senior frontend interview and they hit you with the Diamond Problem. It sounds like...

Read moreDetails
Angular 21: Why Native [class] is 2x Faster than ngClass!

Angular 21: Why Native [class] is 2x Faster than ngClass!

January 20, 2026
Windsurf SWE-1 Featured Image

Windsurf SWE-1: A Groundbreaking Frontier Model Family for Engineers

May 20, 2025
AI Coding Competition Featured Image

LM Arena: The Ultimate Playground for Web Developers to Benchmark AI Language Models

May 20, 2025
TRAE: A Free AI-Powered Code Editor Built by TikTok’s Parent Company

TRAE: A Free AI-Powered Code Editor Built by TikTok’s Parent Company

May 20, 2025
Github LinkedIn Youtube Twitter Pinterest Instagram Reddit

About Me

Adnan Halilovic Blog

Adnan Halilović

Software Developer - Content Writer

I am Adnan Halilović, the man behind the website and channels that you are currently reading and viewing!

I am a software developer with over 15 years of expertise in a variety of fields.

Newsletter

Country:

Email address:


Recent from Instagram

    The Instagram Access Token is expired, Go to the Customizer > JNews : Social, Like & View > Instagram Feed Setting, to refresh it.

© 2022 Adnan Halilovic - Software development content, tips & tricks.

Click to Copy
No Result
View All Result
  • Technologies
  • AI Tips and Tricks
  • Frontend
  • Backend
  • Server
  • Contact
  • About

© 2022 Adnan Halilovic - Software development content, tips & tricks.