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)

4

0 回答 0