0

I have three library that communicate each others some data. In particular I have a MAP that show some positions with markers, a TABLE that show details of each markers and the third library (we call it SHARED) have some service and observables that let to map and table to communicate each other. For example

  1. MAP (click a marker and recall a service of SHARED)
  2. SHARED make a next on observable send id of marker
  3. TABLE is listening, receives id and underline the row of the corresponding marker

I'll show some code of this communication:

  1. MAP recall SHARED when marker is clicked
this._dataSharedService.sendIdMarker(idMarker);
  1. SHARED do next
private idMarker: BehaviorSubject<number> = new BehaviorSubject<number>(undefined);
sharedIdMarker = this.idMarker.asObservable();

sendIdMarker(idMarker: number) {
  this.idMarker.next(idMarker);
}
  1. TABLE receives
this.sharedIdMarkerSubscription = this._dataSharedService.sharedIdMarker.subscribe(idMarker => {
  if (idMarker !== undefined) {
    console.log(idMarker);
    this.selectedRowId = idMarker;
  }
});

I have no problems when I use Angular 10.0.4 and I compile my library normally:

ng build library_name
cd dist/library_dir
npm pack

When I pass to another project with Angular 11.2.10 I have to build my TABLE library with this option in tsconfig.lib.json

{
  ... ,
  "angularCompilerOptions": {
    "enableIvy": false,
    ...
  },
  ...
}

otherwise I get this error when I start the application

ERROR Error: ASSERTION ERROR: Expecting flags [Expected=> number === boolean <=Actual]

At the same time I have to compile MAP library with the same option but setted to true otherwise I get this error when I build the library

Error encountered in metadata generated for exported symbol 'AppConfigService'
Metadata collected contains an error that will be reported at runtime: Only initialized variables and constants can be referenced because the value of this variable is needed by the template compiler.

Compiling library in this way, I'm able to run the application but this particular observable not work!
NOTE that there are other observables from MAP to TABLE and also from TABLE to MAP always passing from SHARED (same structures showed before) and all they work correctly!!
I test also to subscribe directly my application to these observable but not even the application receives the id of marker.

Someone know why this specific observable not work only when I pass to Angular 11?

PS. since my first project was in Angular 10 my libraries are written in Angular 10, then I pass to a project with Angular 11 and I would to use the same libraries (that work perfectly even for this observable)

Edo2610
  • 184
  • 1
  • 9
  • Why not enable Ivy everywhere and resolve the errors that show up instead? – Chrillewoodz Jul 20 '21 at 09:29
  • If I enable Ivy (enableIvy: true) for TABLE library I get the error written in the answer. (ERROR Error: ASSERTION ERROR: Expecting flags [Expected=> number === boolean <=Actual]) If I disable Ivy (enableIvy: false) for MAP library I get the error written in the answer. (Error encountered in metadata generated for exported symbol 'AppConfigService' Metadata collected contains an error that will be reported at runtime: Only initialized variables and constants can be referenced because the value of this variable is needed by the template compiler.) – Edo2610 Jul 20 '21 at 09:30
  • Yes, so resolve those errors instead of ignoring them. Surely there's other people who's encountered the same issues, just google them. – Chrillewoodz Jul 20 '21 at 09:39
  • I'll try to solve them, but however I don't understand why all the other observables work correctly – Edo2610 Jul 20 '21 at 10:14
  • do the working observables use the same service or another one? – wlf Jul 20 '21 at 10:24
  • Other observables are in the same service and they are declared in the same way. For example I have another observable that instead of send only one id of the single selected marker, let me to select multiple markers with a box and then send an array of id to table. The same communication described before with the only difference of argument of the BehaviorSubject – Edo2610 Jul 20 '21 at 10:40

0 Answers0