There is an issue I have discovered with Ng-Idle, Material 6 nad Angular 6
"@ng-idle/core": "^6.0.0-beta.3"
"@ng-idle/keepalive": "^6.0.0-beta.3"
"@angular/core": "^6.1.9"
"@angular/cdk": "^6.4.7"
"@angular/material": "^6.4.7"
The scenario
when ever a user has gone idle, a dialog (popup) displays a countdown how long until the user is logged out of the system. If the user return prior to being logged out with mouse activity, the countdown will halt and the dialog will close/disappear.
Issue
However, in Angular 5, this feature was working fine until I upgraded to Angular 6. When ever the user returns prior to onTimeout
, it fires the onIdleEnd
but the dialog doesn't disappear on mouse activity. I created an Angular 6 app to replicate the issue. I am trying to determine if this is an Ng-Idle or an Angular issue.
Stackblitz showing Mat-Dialog closing after 10 second countdown
Has anyone come across this issue?
I had the same issue. I solved it by pushing the change in angular.
First:
In the constructor of your component add ChangeDetectorRef:
then call it in on onIdleEnd:
StackBlitz solution.
Okay so I can't comment because I have no reputation yet, but I wanted to share how I worked around this. What I did is create a parent <div> element around my dialog title/content which calls a closeMe() function on click. This closeMe() calls the 'this.dialogRef.close()' function which actually does close the dialog box.
When the ng2-idle fires the onIdleEnd observable, I simulate the click on that parent div. To do this, I needed to 'inject' the Idle object into the dialog.
My dialog box component.ts file:
My dialog box html file:
Then in the idle setup function (in another service I have, where ````this.idle``` is injected in the constructor parameters):
It's strange that the direct call to
this.dialogRef.close();
works in onTimeout but not in the onIdleEnd.Anyway, hope this helps until the issue is fixed.