Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

angular add debounce time before putting valu in subject next

import {Component}   from '@angular/core';
import {FormControl} from '@angular/forms';
import {Observable}  from 'rxjs/Observable';
import 'rxjs/add/operator/debounceTime';
import 'rxjs/add/operator/throttleTime';
import 'rxjs/add/observable/fromEvent';

@Component({
  selector: 'my-app',
  template: `<input type=text [value]="firstName" [formControl]="firstNameControl">
    <br>{{firstName}}`
})
export class AppComponent {
  firstName        = 'Name';
  firstNameControl = new FormControl();
  formCtrlSub: Subscription;
  resizeSub:   Subscription;
  ngOnInit() {
    // debounce keystroke events
    this.formCtrlSub = this.firstNameControl.valueChanges
      .debounceTime(1000)
      .subscribe(newValue => this.firstName = newValue);
    // throttle resize events
    this.resizeSub = Observable.fromEvent(window, 'resize')
      .throttleTime(200)
      .subscribe(e => {
        console.log('resize event', e);
        this.firstName += '*';  // change something to show it worked
      });
  }
  ngDoCheck() { console.log('change detection'); }
  ngOnDestroy() {
    this.formCtrlSub.unsubscribe();
    this.resizeSub  .unsubscribe();
  }
} 
Comment

PREVIOUS NEXT
Code Example
Javascript :: Target type ieee.std_logic_1164.STD_LOGIC_VECTOR in variable assignment is different from expression type ieee.std_logic_1164.STD_ULOGIC. 
Javascript :: como fazer elementos que scroll diferente 
Javascript :: vue change input value from console 
Javascript :: angular attach component to body 
Javascript :: KeyEvent event = new KeyEvent(k); event.call(); 
Javascript :: how to make sticky footer with react router 
Javascript :: angular two-way-binding on observable 
Javascript :: reverse a number in javascript without using inbuilt function 
Javascript :: apply event listener on id but why not style 
Javascript :: how to change the model object django in javascript 
Javascript :: react conditional if localhost 
Javascript :: how to translate english to hindi after enter space using javascript 
Javascript :: promises and not callbacks 
Javascript :: es6 for-of loop 
Javascript :: jquery copier dans le presse papier 
Javascript :: most popular company with nodejs 
Javascript :: inferred type is Array<out GroupItem 
Javascript :: noblox.getinfo 
Javascript :: javascript match image attribute value 
Javascript :: strip js for subscription 
Javascript :: rdlc refresh dataset from object 
Javascript :: get each primary colour and add into an array javascript 
Javascript :: passing a variable to the width style div angular 
Javascript :: dustjs compilator 
Javascript :: convert class to functional component online 
Javascript :: keydown check if character is typed javascript 
Javascript :: get random hsl value, javascript 
Javascript :: Back button directive Angular 
Javascript :: js update all links 
Javascript :: xpath cheat sheet using node 
ADD CONTENT
Topic
Content
Source link
Name
6+2 =