Prime Vyapar

Tales from a Developer's Trenches

Importing and using components

Importing and using components
Angular offers two approaches to using a component in other parts of your application: you can utilize it directly(standalone component) or include it within an NgModule.

Code Snippet
Copy
                
                   
import { Component } from '@angular/core'; @Component({ selector: 'app-root', standalone:true, templateUrl: './app.component.html', styleUrl: './app.component.scss', imports:[DemoComponent] }) export class AppComponent { title = 'Prime Vyapar'; }

  • Standalone components can be seamlessly imported into other standalone components.
  • In Angular's development best practices, creating new components as standalone is recommended.

NgModules

NgModules were essential for importing and using components. This has changed with the introduction of standalone components.
  • Declares which components, directives, and pipes belong to the module
  • Makes some of those components, directives, and pipes public so that other module's component templates can use them
  • Imports other modules with the components, directives, and pipes that components in the current module need
  • Provides services that other application components can use

Leave a Comment

This sample demonstrates the full features of Rich Text Editor that includes all the tools and functionalities.

Comments