Skip to content
This repository has been archived by the owner on Oct 13, 2023. It is now read-only.

Textbox value not updated on UI with OnPush Strategy #418

Open
ankit-11tyagi opened this issue Jan 28, 2019 · 1 comment
Open

Textbox value not updated on UI with OnPush Strategy #418

ankit-11tyagi opened this issue Jan 28, 2019 · 1 comment

Comments

@ankit-11tyagi
Copy link

I am using ng2-completer in a component with OnPush change detection strategy. When i update the value of completer's ngModel, it does not reflect on UI. Only when i manually focus on input box, value gets updated. I have also tried calling markforcheck() and detectChanges() manually after updating the value but no luck. Please let me know if i am missing anything here.

import { Component, OnChanges, ChangeDetectionStrategy, ChangeDetectorRef } from '@angular/core';
import { CompleterService } from 'ng2-completer';

@Component({
  selector: 'app-root',
  template: `
  <ng2-completer [(ngModel)]="colorCode" [dataService]="dataService" [minSearchLength]="0"></ng2-completer>  
  <button (click)="updateValue()" >Trigger change detection</button>              
  `,
  changeDetection: ChangeDetectionStrategy.OnPush
})

export class AppComponent   {

  dataService;
  colorCode = "default";

  constructor(
    completerService: CompleterService,
    private cdr: ChangeDetectorRef
    ) {
    this.dataService = completerService.local([
      'red',
      'green',
      'blue',
      'cyan',
      'magenta',
      'yellow',
      'black'
		    ]);
  }

  updateValue(){
    this.colorCode = "red";
    this.cdr.detectChanges();
  }
  
}
@leae-e
Copy link

leae-e commented Jul 10, 2023

Do you remember what the solution to the problem was?
I came across this just now
Thanks

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants