首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >从自定义共享模块角度5绘制子组件

从自定义共享模块角度5绘制子组件
EN

Stack Overflow用户
提问于 2018-04-16 20:13:39
回答 1查看 109关注 0票数 0

我对棱角很陌生,很难在另一个组件中显示一个组件。

模式:我有一个导航栏,使路由器出口使用路由导航到"component1“。然后,在组件1中,我将标记保持不变。如果我导航到组件-2使用路由,它正确地呈现。

main.component.html

代码语言:javascript
复制
<div class="flex">
    <div>
            <router-outlet name="navbar"></router-outlet>
            <div class="container-fluid col-10 offset-2">
                <div class="row">
                    <div class="col-12">
                        <div class="card jh-card shadow">
                            <router-outlet></router-outlet>
                            <router-outlet name="popup"></router-outlet>
                        </div>
                        <jhi-footer></jhi-footer>
                    </div>
                </div>
            </div>
    </div>
</div>

component1.module.ts

代码语言:javascript
复制
import { NgModule, CUSTOM_ELEMENTS_SCHEMA } from '@angular/core';
import { RouterModule } from '@angular/router';

import { ClientSharedModule } from '../shared';
import { COMPONENT1_ROUTE, Component1 } from './';

@NgModule({
    imports: [
      ClientSharedModule,
      RouterModule.forRoot([ COMPONENT1_ROUTE ], { useHash: true }),
    ],
    declarations: [
      Component1
    ],
    entryComponents: [
    ],
    providers: [
    ],
    schemas: [CUSTOM_ELEMENTS_SCHEMA]
})
export class Component1Module {}

component1.component.html

代码语言:javascript
复制
<div class="row">
    <div class="col-md-1"></div>
    <div class="col-md-10">
        <div class=""> searchBar</div>
        <div> some text</div>
    </div>
    <div class="col-md-1"></div>
</div>
<component-2>test</component-2>

component-2.component.ts

代码语言:javascript
复制
import { Component, OnInit } from '@angular/core';

@Component({
  selector: 'component-2',
  templateUrl: './component-2.component.html',
  styles: [
      'component-2.scss'
  ]
})
export class Component2 implements OnInit {

  constructor() {
      console.log('COMPONENT CONSTRUCTED');
  }

  ngOnInit() {
      console.log('COMPONENT INITIALISED');
  }

}

custom-shared.module.ts

代码语言:javascript
复制
import {CUSTOM_ELEMENTS_SCHEMA, NgModule} from '@angular/core';
import {

    Component2Module
} from './component-2/component-2.module';

@NgModule({
  imports: [
    Component2Module,
  ],
  declarations: [
  ],
  entryComponents: [],
  exports: [
    Component2Module
  ],

  schemas: [CUSTOM_ELEMENTS_SCHEMA]
})
export class CustomSharedModule { }

component-2.module.ts

代码语言:javascript
复制
import {NgModule, CUSTOM_ELEMENTS_SCHEMA} from '@angular/core';
import {RouterModule} from '@angular/router';
import {ClientSharedModule} from '../../shared';
import {
    Component2Details,
    Component2,
    component2Route
} from './';

const ENTITY_STATE = [
    component2Route,
];

@NgModule({
  imports: [
      ClientSharedModule,
      RouterModule.forChild(ENTITY_STATE)
  ],
  declarations: [
      Component2,
      Component2Details
  ],
  entryComponents: [
      Component2,
      Component2Details
  ],
  schemas: [CUSTOM_ELEMENTS_SCHEMA]
})

export class Component2Module {
    constructor() {}
}

我换了零件的真名。实际上,我在编译时和执行时都没有错误。我相信这与范围或注射有关,但我找不到解决办法。如果有人能给我一些帮助,我会非常感激的。

附加信息: Jhipster v4.14.2单片应用程序。角5+

提前谢谢。文森特湾

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2018-04-18 07:58:36

问题解决了,我的错误是,如果我在compent2模块中导出component2,然后在我的共享模块中导入这个模块,那么在我导入共享模块的任何地方,组件都是可用的。

解决方案是直接从共享模块导出/声明component2。然后,无论我在哪里导入共享模块,它都是可用的。

希望这能帮到一些人。再见

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/49865505

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档