Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Services not being injected when annotated with @MultiWindowService #41

Closed
Vargrats opened this issue Oct 1, 2019 · 7 comments
Closed
Assignees
Labels
bug Something isn't working

Comments

@Vargrats
Copy link

Vargrats commented Oct 1, 2019

Hello,

I'm trying to integrate golden layout in a browser application using Angular 8.2 and it seems that my services are created without their injected components.

In the example below, the injected component (httpClient, calendarService and dutyService are all undefined when they are used in the service's functions.

If I remove the @MultiWindowService, everything works as intended however when I pop-out a component, it no longer share the services with the main window (as intended)

This is one of my service:

@Injectable({
  providedIn: 'root'
})
@MultiWindowService<CategoryService>()
export class CategoryService extends BaseService {
  constructor(private httpClient: HttpClient, private calendarService: CalendarService, private dutyService: DutyService) {
    super('/api/dutyCategory');
  }
<Rest of the service>

The layout is defined in one of my components like this:

window['$'] = $;
// Define all component types known at compile time to the golden-layout binding.
// It's possible to modify these at runtime using the `ComponentRegistryService`
const componentTypes: ComponentType[] = [
  {
    name: 'DutyListComponent',
    type: DutyListComponent
  },
  {
    name: 'DutyDetailComponent',
    type: DutyDetailComponent
  },
  {
    name: 'DutyScheduleContactComponent',
    type: DutyScheduleContactComponent
  },
  {
    name: 'CalendarComponent',
    type: CalendarComponent
  }
];
@NgModule({
  entryComponents: [DutyListComponent, DutyDetailComponent, DutyScheduleContactComponent, CalendarComponent],
  declarations: [DutyConsultationComponent],
  imports: [SharedModule, ComponentsModule, DutyConsultationRoutingModule, GoldenLayoutModule.forRoot(componentTypes)],
  providers: [],
  exports: [DutyConsultationComponent]
})
export class DutyConsultationModule {}

There are no errors when I run ng build.

Here are the relevant lines in my package.json:

"@angular/animations": "^8.2.1",
    "@angular/cdk": "^8.2.1",
    "@angular/common": "^8.2.1",
    "@angular/compiler": "^8.2.1",
    "@angular/core": "^8.2.1",
    "@angular/forms": "^8.2.1",
    "@angular/material": "^8.2.1",
    "@angular/platform-browser": "^8.2.1",
    "@angular/platform-browser-dynamic": "^8.2.1",
    "@angular/router": "^8.2.1",
    "golden-layout": "^1.5.9",
    "ngx-golden-layout": "0.0.27",

Can anyone help?

Thanks in advance!

@martin31821 martin31821 added the bug Something isn't working label Oct 2, 2019
@martin31821 martin31821 self-assigned this Oct 2, 2019
@martin31821
Copy link
Member

Can you out your tsconfig here, too? I assume you're not using ivy, which causes this to break.

@Vargrats
Copy link
Author

Vargrats commented Oct 2, 2019

Is Ivy a package from npm? If so, no we are not using it.

Here is my tsconfig:

{
  "compileOnSave": false,
  "compilerOptions": {
    "baseUrl": "./",
    "importHelpers": true,
    "outDir": "./dist/out-tsc",
    "sourceMap": true,
    "declaration": false,
    "module": "es2015",
    "moduleResolution": "node",
    "emitDecoratorMetadata": true,
    "experimentalDecorators": true,
    "target": "es5",
    "paths": {
      "@env/*": ["environments/*"],
      "core-js/es7/reflect": [
        "node_modules/core-js/proposals/reflect-metadata"
      ],
      "core-js/es6/*": ["node_modules/core-js/es/*"]
    },
    "typeRoots": ["node_modules/@types"],
    "types": ["jquery"],
    "lib": ["es2018", "dom"]
  }
}

And my tsconfig.app

{
  "extends": "../tsconfig.json",
  "compilerOptions": {
    "outDir": "../out-tsc/app",
    "types": ["jquery"]
  },
  "exclude": [
    "test.ts",
    "**/*.spec.ts"
  ]
}

Thanks again for your time.

@martin31821
Copy link
Member

As I suspected, this happens when not using angular ivy, I'll try to fix it for both variants.

@sagunpandey
Copy link

@martin31821 Has there been any update? I am also using non-Ivy AOT compilation and I am facing a similar issue. My multi-window services are being injected but service properties are all undefined.

@sagunpandey
Copy link

@Vargrats Did you come up with any solution?

@martin31821
Copy link
Member

Fixed in 0.0.30

@sagunpandey
Copy link

@martin31821 I am still facing the issue after updating to 0.0.30. Everything works just fine in the development build. But as soon as you use production build the injected services have their properties undefined.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants