Angular 19: Use a component from a module in another component

Discussão em 'Angular' iniciado por sunics, Março 10, 2025.

  1. sunics

    sunics Guest

    we use Angular 19. is it possible to use a component from a module in another component from the same module? if yes, how can i use it without the import in the first component?

    partone.module.ts

    import { NgModule } from '@angular/core';
    import { CommonModule } from '@angular/common';
    import { componentone } from './components/one/one.component';
    import { componenttwo } from './components/two/two.component';

    @NgModule({
    declarations: [
    ],
    imports: [
    CommonModule, componentone, componenttwo
    ],
    exports: [
    componentone, componenttwo
    ]
    })
    export class partoneModule { }


    one.component

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

    @Component({
    selector: 'comp-one',
    imports: [],
    standalone: true,
    templateUrl: './one.component.html',
    styleUrl: './one.component.scss'
    })
    export class componentone {

    }


    two.component

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

    @Component({
    selector: 'comp-two',
    imports: [],
    standalone: true,
    templateUrl: './two.component.html',
    styleUrl: './two.component.scss'
    })
    export class componenttwo {

    }


    one.component.html

    <comp-two></comp-two>

    Continue reading...

Compartilhe esta Página