【问题标题】:Difficulty to open component from another module难以从另一个模块打开组件
【发布时间】:2019-07-31 02:20:39
【问题描述】:

我的例子是:州和市。

我想在视图城市上创建一个带有固定项目的下拉列表,例如:“添加新项目”。当点击此项时,模型会出现一个状态组件来添加新的状态。

我已经在 CityModule 中导入了 StateModule,但是当我点击打开任何城市视图时,它会打开状态而不是城市...(下图)

city.module.ts

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

Cidade = 城市 | Estado = 州 |地籍 = 注册

编辑

我还没有做下拉列表

<button (click)="modal()">Click Here</button>
modal() {
   this.ngbModalService.open(AddStateComponent,{size: 'lg'});
}

路线

export const CityRouterConfig: Routes = 
[
    {
        path: '', component: CityComponent,
        data: {
            title: 'City',
            urls: [{ title: 'Cities', url: '/cidade' }, { title: 'City' }]
        },
        children: [
            ...,
            { path: 'add', component: AddCityComponent,
                data: {
                    title: 'City',
                    urls: [{ title: 'Cities', url: '/cidade' }, { title: 'City' }]
                }
            }      
        ]
    }
]

关于重复

我的opencomponent

链接是"string" html

我不明白该链接以及我必须做些什么来解决我的问题...

【问题讨论】:

  • 请粘贴您调用State组件的代码部分,如果可能的话,也请粘贴模板的相关部分。您提供的详细信息越多,就越容易帮助您。 :)
  • 看起来你的 router.module 定义不好,但很难知道
  • @LeoHenrique 你想在另一个组件中打开一个组件吗?
  • @AkaiCrystal 是的,我想在添加新城市时添加新州(必要时)
  • @BrunoFarias 我更新了帖子

标签: angular


【解决方案1】:

我用共享模块解决了

city.module.ts

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

state.module.ts

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

shared.module.ts

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2018-03-09
    • 2016-08-28
    • 1970-01-01
    • 2020-05-12
    • 1970-01-01
    • 2018-03-26
    • 2018-03-29
    • 2018-06-12
    相关资源
    最近更新 更多