0

Very classical situation where I try to use some component in another module :

Foreign component :

import { Component, ViewEncapsulation,
  ElementRef, ViewChild, Input, Output,
  EventEmitter } from '@angular/core';

declare var __moduleName: string

@Component({
  moduleId:    __moduleName,
  selector:    'bidule',
  templateUrl: 'bidule.html',
  styleUrls:   [],
  encapsulation: ViewEncapsulation.None
})
export class BiduleComponent {

  @Input() config: { }

  constructor(protected elRef: ElementRef) {
  }

}
// template : <p>basic text</p>

Foreign module :

import { NgModule }       from '@angular/core';
import { CommonModule }   from '@angular/common';

import { BiduleComponent } from './bidule'

@NgModule({
  imports: [
  ],
  declarations: [
    BiduleComponent
  ],
  exports: [
    BiduleComponent
  ]
})
export class BiduleModule {}

Main component :

...
import { BiduleComponent }       from '../../bidule/bidule'
...
// template : <bidule></bidule>

Main module :

import { BiduleModule }          from '../../bidule/module'
// ...
@NgModule({
  imports: [
    // ...
    BiduleModule
  ]
})

I believe I checked everything :

https://stackoverflow.com/questions/44429996#44430230

If you have any idea. Thanks in advance.

(bidule is a french word for thingamajig)

ChrisGPT was on strike
  • 127,765
  • 105
  • 273
  • 257
spin
  • 31
  • 3

1 Answers1

0

You only need to import the Foreign module in the Main module and use the <bidule></bidule> to any component of Main Module. You are right that exporting the BiduleComponent but you don;t need to import it directly to Main Component, it's enough that you import the Foreign Module to Main Module.

macvag
  • 401
  • 4
  • 11
  • It persists, otherwise I would have validated your answer :) – spin Sep 15 '17 at 15:13
  • Try to remove moduleId and encapsulation, and pls remove the // from template on Main Component. Also make your code as simple as possible for start(remove the declarations from contrsuctors if not needed). To be able to identify where the issue starts to appear. – macvag Sep 15 '17 at 22:27