복붙노트

[ANGULAR] rxjs - keyup 이벤트가있는 distinctIntilchanged ()

ANGULAR

rxjs - keyup 이벤트가있는 distinctIntilchanged ()

해결법


  1. 1.문제는 항상 GetData를 만듭니다. 먼저 변경 사항을 보시고 스위치 맵을 사용하여 데이터를 가져옵니다. 그래서 당신은 관찰 할 수있는 변화가 있어야합니다. [(ngmodel)의 입력이 아닌 "FormControl"을 사용하십시오. 그래서, 당신의 .html에서

    문제는 항상 GetData를 만듭니다. 먼저 변경 사항을 보시고 스위치 맵을 사용하여 데이터를 가져옵니다. 그래서 당신은 관찰 할 수있는 변화가 있어야합니다. [(ngmodel)의 입력이 아닌 "FormControl"을 사용하십시오. 그래서, 당신의 .html에서

    <input type="text" [formControl]="search">
    

    코드는해야합니다

      search= new FormControl();       //Declare the formControl
    
      constructor() {}
    
      ngOnInit() {
        this.search.valueChanges.pipe(
             debounceTime(400),
             distinctUntilChanged(),
             tap((term)=>{
                  //here the value has changed
                  this.loadingIndicator = true;
             }),
             switchMap(filteredValue=> {
                  //We not return the value changed, 
                  return this.svc.getData().pipe(
                         map(_co => {
                             return _co.filter(...)
                         }),
                         tap(()=>{
                             this.loadingIndicator=false;
                         }))
              })).subscribe(result=>{
                 this.result=result
              })
      }
    
  2. from https://stackoverflow.com/questions/50732416/rxjs-distinctuntilchanged-with-keyup-event by cc-by-sa and MIT license