Use dependency in 2 different modules

Asked

Viewed 110 times

-2

How do I have in different modules, the same component in the declarations?

Ex:

estado.modulets.

@NgModule({
  imports: [...],
  declarations: [ AdicionarEstado, ... ]
  ...
})

city.modulets.

@NgModule({
  imports: [...],
  declarations: [ AdicionarEstado, ... ]
  ...
})

I need this because I will have a select that, your first item will be a fixed button that will open a modal to register a state, besides bringing the registered ones. This will be done on the city register... (when necessary).

EDIT

With import from the state in the city

city.modulets.

@NgModule({
  imports: [ EstadoModule, ...],
  declarations: [ ... ]
  ...
})

inserir a descrição da imagem aqui

  • You can put the Added in the declarations and in the State Exports, and then add the State in the City as it was exported by the Statedule can be used in the Citiquedule that is importing everything that is declared in the State. Have you tried it? I believe it will solve your problem.

  • I did that, but when I open the view of the city, the state is loaded...

  • I put an example for you to see

  • 1

    Dude, Angular doesn’t allow you to declare 1 component in two different modules... what you can do is to encapsulate your component in another module, but I don’t have ctz if I understand your question.

  • I put this on Edit, I tried to do with the module import, but when I load a city view in the case, it opens a state view...

  • The idea is to register a state within the city view, using a modal, I described this also in the post...

Show 1 more comment

1 answer

2


I managed to do with Shared module

city.modulets.

@NgModule({
  imports: [ SharedModule, ...],
  declarations: [ ... ]
  ...
})

estado.modulets.

@NgModule({
  imports: [ SharedModule, ...],
  declarations: [ ... ]
  ...
})

Shared.module.ts

@NgModule({
    imports: [
    ],
    declarations: [
        AdicionarEstadoComponent
    ],
    providers: [
    ],
    bootstrap: [
    ],
    exports: [
        AdicionarEstadoComponent
    ]
})
export class SharedModule { }

Browser other questions tagged

You are not signed in. Login or sign up in order to post.