Skip to content

Conversation

@StefanKern
Copy link

@StefanKern StefanKern commented Jul 31, 2017

When using this element with the "multiple" option, the value was not updated when it was changed from outside.

This was because "ngOnChanges" only performes a value checking not, a deep value checking. (Source: https://stackoverflow.com/questions/34796901/angular2-change-detection-ngonchanges-not-firing-for-nested-object ).
Beucause with the "multiple" option, "value" is a "string[]", a simple "ngOnChanges" check is not enough enough, it needs to check on "ngDoCheck".

Code:

    ngDoCheck() {
        if ($.isArray(this.value)) {
            if (this.oldValueLength !== this.value.length) {
                this.oldValueLength = this.value.length;
                this.setElementValue(this.value);
            }
        }
    }

This code only check, if the value is an array and sets the new value in an array. To detect the change,
private oldValueLength = 0;
Is added, to keep track of the last lenght. (changes from null to array where already detected.)

When using this element with the "multiple" option, the value was not updated when it was changed from outside.

This was because "ngOnChanges" only performes a value checking not, a deep value checking. (Source: https://stackoverflow.com/questions/34796901/angular2-change-detection-ngonchanges-not-firing-for-nested-object ).
Beucause with the "multiple" option, "value" is a "string[]", a simple "ngOnChanges" check is not enough enough, it needs to check on "ngDoCheck".

Code:
    ngDoCheck() {
        if ($.isArray(this.value)) {
            if (this.oldValueLength !== this.value.length) {
                this.oldValueLength = this.value.length;
                this.setElementValue(this.value);
            }
        }
    }^


This code only check, if the value is an array and sets the new value in an array. To detect the change, 
    private oldValueLength = 0;
Is added, to keep track of the last lenght. (changes from null to array where already detected.)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant