akserg / ng2-slim-loading-bar

Angular 2 component shows slim loading bar at the top of the page.
MIT License
358 stars 93 forks source link

Expression has changed after it was checked. Previous value: '0'. Current value: '1'. #29

Open stephane-dereppe opened 7 years ago

stephane-dereppe commented 7 years ago

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

[x ] bug report => check the FAQ and search github for a similar issue or PR before submitting
[ ] support request => check the FAQ and search github for a similar issue before submitting
[ ] feature request

Current behavior

Sometimes, an exception is raised after starting the loading bar :

Exception raised : zone.js:140 Uncaught Error: Error in ./SlimLoadingBarComponent class SlimLoadingBarComponent - inline template:3:32 caused by: Expression has changed after it was checked. Previous value: '0'. Current value: '1'.

It is not in each case and I really don't know what can trigger this error.

I have to add that as said here I do not have the problem when is enable Prod Mode...

But in dev mode (local dev), I get this errors.

Expected/desired behavior

No error.

Reproduction of the problem If the current behavior is a bug or you can illustrate your feature request better with an example, please provide the steps to reproduce and if possible a minimal demo of the problem via https://plnkr.co or similar.

What is the expected behavior?

What is the motivation / use case for changing the behavior?

Please tell us about your environment:

akserg commented 7 years ago

Hi @schtrym,

It the issue still exists?

stephane-dereppe commented 7 years ago

I added

    ngAfterViewInit() {
        this._loadingBarService.loadingBarEvent.subscribe(bool => {
            this.visible = bool;
            this._changeDetectorRef.detectChanges();
        });
    };

to avoid the error

akserg commented 7 years ago

Can you, please create the PR?

usmanatron commented 7 years ago

@schtrym can you please give a bit more context regarding where you put this? I'm happy to make the changes and send a PR (this is causing me loads of problems!) if you're happy for me to do so?

akserg commented 7 years ago

Hi @schtrym I have created PR to fix your issue. Can you, please have a look?

JiahaoLi commented 7 years ago

Have the same issue. After making couple of tries, I found to add resolve in routing for view page can avoid this issue. And also wait for PR for this issue.