Modern Angular: Standalone Components

Posted by


Angular Moderno is a modern implementation of Angular that allows developers to create standalone components that can be easily integrated into any Angular project. In this tutorial, we will cover the basics of creating standalone components using Angular Moderno.

First, let’s start by creating a new Angular project. You can do this by running the following command in your terminal:

ng new my-angular-project --routing=false --style=scss

Next, we need to install Angular Moderno. You can do this by running the following command in your terminal:

npm install @angular/moderno --save

Once Angular Moderno is installed, we can start creating our standalone component. Create a new folder inside the src/app directory called ‘standalone-components’, and inside this folder, create a new file called ‘my-standalone-component.component.ts’.

Inside this new file, we will define our standalone component. Here’s an example of how you can define a simple standalone component:

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

@Component({
  selector: 'app-my-standalone-component',
  template: `
    <div>
      <h1>Hello, I am a standalone component!</h1>
    </div>
  `,
  styles: []
})
export class MyStandaloneComponentComponent {}

Now that we have defined our standalone component, we need to register it with Angular Moderno. To do this, open the src/app/app.module.ts file and import the AngularModernoModule from ‘@angular/moderno’. Next, add MyStandaloneComponentComponent to the declarations array:

import { NgModule } from '@angular/core';
import { AngularModernoModule } from '@angular/moderno';
import { AppComponent } from './app.component';
import { MyStandaloneComponentComponent } from './standalone-components/my-standalone-component.component';

@NgModule({
  declarations: [
    AppComponent,
    MyStandaloneComponentComponent
  ],
  imports: [
    AngularModernoModule
  ],
  providers: [],
  bootstrap: [AppComponent]
})
export class AppModule { }

Now our standalone component is registered with Angular Moderno, and we can start using it in our Angular project. To use the standalone component, you can simply add it to any Angular component’s template like this:

<app-my-standalone-component></app-my-standalone-component>

And that’s it! You have successfully created a standalone component using Angular Moderno. This allows you to create reusable components that can be easily integrated into any Angular project.

In conclusion, Angular Moderno provides a modern and efficient way to create standalone components in Angular. By following the steps outlined in this tutorial, you can create standalone components that are easily reusable and can be integrated into any Angular project with ease.

0 0 votes
Article Rating

Leave a Reply

43 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
@angelicaruiz5027
2 hours ago

Parabéns pela aula, muito boa como sempre!

@rogeriotadeudosreis342
2 hours ago

Boa noite Loiane, tudo bem ? por favor, poderia criar um vídeo tutorial só sobre rotas com angular 18 standalone ?
Estou meio confuso com essa nova abordagem. Obrigado

@rogeriotadeudosreis342
2 hours ago

Boa noite Loiane, muito obrigado pela excelente aula, foi muito bom estar cientes dessa alteraçao no angular

@daviamerico2268
2 hours ago

não gosto desse negocio, estou aprendendo angular agora, não sei se devo aprender o atual ou o mais legado, vou ficar em standalone mas usando esse RxJs

@PauloLucasSilva
2 hours ago

Gostei muito do video Loiane. Tem me ajudado bastante.

@viniciusverasdossantos3893
2 hours ago

A recomentação é nao usar mais modulos?

@LucelmoMartins
2 hours ago

já tentei React, Vue, e agora tentando Angular. só quero saber o infeliz que criou frameworks

@fernandohungaro
2 hours ago

Como sempre mais um ótimo video!

@Naicson11
2 hours ago

Mestra

@lobotech4866
2 hours ago

Que extensão do VS code vc usa de ícones?

@lm7_b
2 hours ago

Aulas incríveis, conteúdos incríveis etc etc
Muito obrigado Loiane!!!!!!

@antoniofcable
2 hours ago

Excelente aula. Vou tentar aplicar no meu app

@carlossouza5478
2 hours ago

ótimo conteudo

@kallnascimento7
2 hours ago

E em relação à rotas dentro de rotas, como fica? por exemplo: estoque/produto/novo

@damianmeneses4382
2 hours ago

Excelente video, eu tinha iniciado um projetinho há uns meses atrás e fiquei com duvida dos standalones e vi q me preocupei a toa kkkk, já tô migrando a minha aplicação novamente agora kkkk, muitissimo obrigado e continuo no aguardo do video de signals

@AnaeLucy
2 hours ago

que aulão incrivel
amo de mais a didatica

@brbr1414
2 hours ago

In 2020 I took Loiane Angular course. Never worked with web dev but it opened ALL the doors for me. 4 years later I'm a RPA consultant making dollars here in Brasil. Thank you for your greatness and humility to share great master. Cheers from Belo Horizonte! Keep empowering ppl.

@pedrohenriqueliraferreira1224
2 hours ago

Lembro de estar começando com o Angular a 3 anos atrás, seus vídeos me ajudaram muito!

@FelipedosSantosAssis
2 hours ago

Muito obrigado pelo vídeo Loiane! Como sempre muito didádico, e direto ao ponto. Eu confesso que tenho medo de mudanças radicais no Ângular, mas os Standalone Components e API chegaram para simplificar ainda mais nossa vida!

@jfbarkokebas1902
2 hours ago

Que maravilha ter um conteúdo novo seu Loiane. Amo seus vídeos!
Uma dúvida, as JSPs são tão poderosas. Por que o mercado pede tanto Angular?

43
0
Would love your thoughts, please comment.x
()
x