Nebular: NbWindowService - context no longer works

Created on 23 Feb 2019  路  8Comments  路  Source: akveo/nebular

Issue type

I'm submitting a ... (check one with "x")

  • [x] bug report
  • [ ] feature request

Issue description

Current behavior:

I just upgraded from 3.0.0 to 3.3.0, and now the context property no longer works when creating a window.

It appears the example app/demo is not working either:
https://akveo.github.io/nebular/example/window/template-window.component

Expected behavior:

When passing in an object as the context, I would expect my component to have access to that data, according to the docs: "For components, this data will be set as component properties."

Steps to reproduce:

Pass a context property to the configuration of a window.

Related code:

The code below works on 3.0.0, but after the upgrade it doesn't work:

parent.component.ts:
this.windowService.open(MyComponent,
      { title: 'Details', context: { records: row.data} }
    );

my.component.ts:
  ngOnInit() {
  // should output data
    console.log(this.records);
  }

Other information:

npm, node, OS, Browser

npm 5.6.0

Angular, Nebular

    "@angular/cdk": "^7.2.1",
    "@angular/common": "^7.2.1",
    "@angular/compiler": "^7.2.1",
    "@angular/core": "^7.2.1",
    "@angular/forms": "^7.2.1",
    "@angular/http": "^7.2.1",
    "@nebular/auth": "3.3.0",
    "@nebular/bootstrap": "3.3.0",
    "@nebular/security": "3.3.0",
    "@nebular/theme": "3.3.0",
urgent bug components

Most helpful comment

Thanks, @swbradshaw. So the issue is that context is set after window component was initialized, right? We'll look into this. As a workaround, for now, you can inject window context using NB_WINDOW_CONTEXT injection token. This way it will be available right off.

import { NB_WINDOW_CONTEXT } from '@nebular/theme/components/window/window.options';
//...
class MyComponent {
  text: string;

  constructor(@Inject(NB_WINDOW_CONTEXT) context) {
    this.text = context.text;
  }
}

All 8 comments

I just tested this fix on 3.4.1, and it does not work.

If I setup breakpoints in the code, I can see that NbWindowService.prototype.appendWindow calls ref.changeDetectorRef.detectChanges(); but the code never continues; a breakpoint on the next line return ref; is never hit. When the window launches my component, I have a breakpoint in ngOnInit, and the context object is missing. It seems like the Window component doesn't attach until the ngAfterViewChecked life cycle, which is well after the component has done its init.

Downgrading back to an older version again.

@nnixaa Can this be reopened? The problem was never fixed.

@swbradshaw I encountered this problem too. But updating to version 3.4.1 has fixed the bug for me.

@swbradshaw I encountered this problem too. But updating to version 3.4.1 has fixed the bug for me.

It depends how you are using the context. If you were referencing it in another component, which is the use case provided when I opened this issue, that has not been fixed.

@swbradshaw Could you please show how exactly windowService.open call and component you passing to it look like in your case? I can't see any issues. See example stackblitz.

Thanks, @swbradshaw. So the issue is that context is set after window component was initialized, right? We'll look into this. As a workaround, for now, you can inject window context using NB_WINDOW_CONTEXT injection token. This way it will be available right off.

import { NB_WINDOW_CONTEXT } from '@nebular/theme/components/window/window.options';
//...
class MyComponent {
  text: string;

  constructor(@Inject(NB_WINDOW_CONTEXT) context) {
    this.text = context.text;
  }
}
Was this page helpful?
0 / 5 - 0 ratings