Dialogs fail if visible by default
I'm submitting a ... (check one with "x")
[x] bug report => Search github for a similar issue or PR before submitting
[ ] feature request => Please check if request is not on the roadmap already https://github.com/primefaces/primeng/wiki/Roadmap
[ ] support request => Please do not submit support request here, instead see http://forum.primefaces.org/viewforum.php?f=35
Plunkr Case (Bug Reports)
Current behavior
Am getting error when i open a dialog at the time of my component initialization.
ERROR Error: Uncaught (in promise): TypeError: Cannot read property 'offsetWidth' of undefined TypeError: Cannot read property 'offsetWidth' of undefined at DomHandler.getOuterWidth (domhandler.js:197) at Dialog.center (dialog.js:111) at Dialog.show (dialog.js:50) at Dialog.set [as visible] (dialog.js:40) at updateProp (core.es5.js:11023) at checkAndUpdateDirectiveInline (core.es5.js:10721) at checkAndUpdateNodeInline (core.es5.js:12137) at checkAndUpdateNode (core.es5.js:12105) at debugCheckAndUpdateNode (core.es5.js:12734) at debugCheckDirectivesFn (core.es5.js:12675) at Object.View_PurchaseViewComponent_0.co [as updateDirectives] (PurchaseViewComponent.html:204) at Object.debugUpdateDirectives [as updateDirectives] (core.es5.js:12660) at checkAndUpdateView (core.es5.js:12072) at callViewAction (core.es5.js:12387) at execComponentViewsAction (core.es5.js:12333) at DomHandler.getOuterWidth (domhandler.js:197) at Dialog.center (dialog.js:111) at Dialog.show (dialog.js:50) at Dialog.set [as visible] (dialog.js:40) at updateProp (core.es5.js:11023) at checkAndUpdateDirectiveInline (core.es5.js:10721) at checkAndUpdateNodeInline (core.es5.js:12137) at checkAndUpdateNode (core.es5.js:12105) at debugCheckAndUpdateNode (core.es5.js:12734) at debugCheckDirectivesFn (core.es5.js:12675) at Object.View_PurchaseViewComponent_0.co [as updateDirectives] (PurchaseViewComponent.html:204) at Object.debugUpdateDirectives [as updateDirectives] (core.es5.js:12660) at checkAndUpdateView (core.es5.js:12072) at callViewAction (core.es5.js:12387) at execComponentViewsAction (core.es5.js:12333) at resolvePromise (zone.js:712) [angular] at resolvePromise (zone.js:683) [angular] at :4200/polyfills.bundle.js:6851:17 [angular] at Object.onInvokeTask (core.es5.js:4136) [angular] at ZoneDelegate.invokeTask (zone.js:397) [angular] at Zone.runTask (zone.js:165) [
=> angular] at drainMicroTaskQueue (zone.js:593) [ ] at HTMLAnchorElement.ZoneTask.invoke (zone.js:464) [ ]
And snippet of my dialog code as follows,
<p-dialog header="New GRN - Select Order" [(visible)]="isSelectPODialogVisible">
<div style="max-height: 550px;" class="posearchDialog">
// content to show in dialog
</div>
</p-dialog>
Note: It is working fine if i open a dialog after component initialization is done.
Expected behavior
Dialog to open and show its content
Minimal reproduction of the problem with instructions Re-Produce steps:
- Set [(visible)] flag of an dialog to true by default and put in one component's template(lets say Hero's Details).
- Use Router and Navigate to Hero's Details component from another component.
What is the motivation / use case for changing the behavior?
Please tell us about your environment:
- Angular version: 4.0.0
- PrimeNG version: 4.0.0-rc.2
- Browser: [all | Chrome 56.0.2924.87 (64-bit) | Firefox 52.0.1 (64-bit) | IE XX | Safari XX | Mobile Chrome XX | Android X.X Web Browser | iOS XX Safari | iOS XX UIWebView | iOS XX WKWebView ]
-
Language: [all | TypeScript 2.2.2 | ES6/7 | ES5]
-
Node (for AoT issues):
node --version=
@angular/cli: 1.0.0 node: 6.9.5 os: win32 x64
Same problem here!
Same here, going back to 2.0.5 fix the issue but styles are a bit broken with Ng4.
Also this happens when the page loads with the variable set to true, basically initializing before it should.
It effectively fixes if i put my initialization code into ngAfterViewInit.
Looks like back to 4 rc 1 is enough. It solved for me.
@giovstef75 after RC1 it worked without doing anything?
That's right. Just get back from rc2 to rc1
Oh he just published a few seconds ago.
@luchillo17 what do you mean?
Oh no wait, it's working for me with RC.2.
Mmmmh, that's quite weird...
It breaks for me when using initialization of the isVisible variable in constructor or ngOnInit, but it works again when i put such initialization in ngAfterViewInit.
Also worth noticing i'm using the async pipe to fetch that value from @ngrx/store.
@giovstef75 Can you check where do you set the isVisible variable?
My case is slightly different: the isvisible variable has a default value (false) set at declaration and it's set to true inside the subscription of an observable. I subscribe in the ngOnInit, but obviously it means nothing.
@giovstef75 That was almost the same as my issue, i was using the async pipe and the error in my case was because i have Redux set up with Webpack's HMR and LocalStorage persistance, so if i saved file or just closed and opened the Electron app when the dialog was open, the variable value ended up set up to true inside the ngOnInit subscription after the reload, thus my fix was as simple as to subscribe in the ngAfterViewInit hook.
I am seeing the same problem. To fix I just set visible to false and set it to true in ngAfterViewInit. @giovstef75 I bet your observable is returning before ngAfterViewInit, maybe you could try moving your call there?
@bfkelsey Mmmmh, no way. That's my structure: the main component contains the p-dialog and a router outlet container. The componet's firing the event I subscribed for is displayed inside the router outlet, and it fires on a click button event. So the afterviewinit of the main component has gone... Anyway, just in case, I tried to move the subscription in the afterviewinit with no effect. I'm stuck at rc1...
When I set visible to p-dialog, cause this issue. here it's my solution
`<p-dialog header="Title" #dialog> Content
@ViewChild('dialog') vcDialog; ngAfterViewInit() { this.vcDialog.visible = true ; } `
None of the above worked for me. Pretty critical issue. Pretty sure this is the culprit: https://github.com/primefaces/primeng/commit/ec06e44f3ac271485f56b0191726fc129042d91c#diff-867ece5a2023e0d7ca72796c19d636e3L147
@leachryanb So initializing to false and move all initialization of the visible variable to the ngAfterViewInit hook didn't worked for you?
It's very likely that such commit is the trouble maker, but aside from the workaround mentioned i can't help much since i put it to work like that.
I have the same problem:
ERROR TypeError: co.showDialog is not a function
at Object.eval [as handleEvent] (AppComponent.html:5)
at callWithDebugContext (core.es5.js:13013)
at HTMLButtonElement.