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

InputSwitch not firing change detection on external value change with Push Strategy #6434

Closed
meeroslav opened this issue Aug 31, 2018 · 1 comment
Assignees
Labels
Type: Bug Issue contains a bug related to a specific component. Something about the component is not working
Milestone

Comments

@meeroslav
Copy link

meeroslav commented Aug 31, 2018

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)
https://stackblitz.com/edit/github-kxjjv5?file=src%2Fapp%2Fapp.component.ts

Current behavior
The writeValue method does not fire change detection.
When using ChangeDetectionStrategy.OnPush value gets set later and change doesn't propagate.

Expected behavior
The component should work same with and without the OnPush change detection strategy.

Minimal reproduction of the problem with instructions
When you disable ChangeDetectionStrategy.OnPush it works, but with change detection on UI doesn't refresh, because writeValue doesn't trigger the change event.

What is the motivation/use case for changing the behavior?
InputSwitch used within components with OnPush strategy do not get value properly initialized. This is because the method writeValue is called after the component has been drawn and initialized, and change is never propagated.

Please tell us about your environment:
Linux Ubuntu, Yarn, Webstorm

  • Angular version: 5.X
    6.1.1

  • PrimeNG version: 5.X
    6.1.3

  • Browser: all

  • Language: all

meeroslav added a commit to meeroslav/primeng that referenced this issue Sep 4, 2018
@cagataycivici cagataycivici changed the title bug: p-inputSwitch not firing change detection on external value change InputSwitch not firing change detection on external value change with Push Strategy Sep 18, 2018
@cagataycivici cagataycivici self-assigned this Sep 18, 2018
@cagataycivici cagataycivici added the Type: Bug Issue contains a bug related to a specific component. Something about the component is not working label Sep 18, 2018
@cagataycivici cagataycivici added this to the 6.1.4 milestone Sep 18, 2018
@cagataycivici
Copy link
Member

Here is an example that will work with upcoming 6.1.4

<p-inputSwitch [(ngModel)]="checked"></p-inputSwitch>
import {Component,ChangeDetectionStrategy,ChangeDetectorRef} from '@angular/core';

@Component({
    templateUrl: './inputswitchdemo.html',
    changeDetection: ChangeDetectionStrategy.OnPush
})
export class InputSwitchDemo {

    checked: boolean = false;

     constructor(private cd: ChangeDetectorRef) {}

    ngOnInit() {
        setTimeout(() => {
            this.checked = true;
            this.cd.markForCheck();
        }, 2000);
    }
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Type: Bug Issue contains a bug related to a specific component. Something about the component is not working
Projects
None yet
Development

No branches or pull requests

2 participants