angular - RxJS -- How to make a timer trigger by click a button when using RxJS? -


@component({     template: ` <div>                     <a *ngif="!sending" (click)="send()">send</a>                     <span *ngif="sending" >{{seconds}} s</span>                 </div>`,     selector: 'password-reset-form' }) export class passwordresetformcomponent implements oninit {      sending:boolean = false;     seconds:number = 60;     counterobservable = new subject();       constructor(public authservice:authservice, public router:router, public formbuilder:formbuilder) {      }      ngoninit() {          this.counterobservable.subscribe(()=> {             this.seconds --;         }, null, ()=> {             this.seconds = 60;             this.sending = false;         });     }      send() {          this.sending = true;          this.counterobservable.next(observable.interval(1000).take(60));     } } 

hey,i try using ng2 , rxjs make timer,when click send button,it display 60s timer,but spent lot of time , still don't know how use rxjs it. appreciate if can me.

something should work:

@component({     template: ` <div>                     <a *ngif="!sending" (click)="send()">send</a>                     <span *ngif="sending" >{{seconds}} s</span>                 </div>`,     selector: 'password-reset-form' }) export class passwordresetformcomponent implements oninit {      sending:boolean = false;     seconds:number = 60;          constructor(public authservice:authservice, public router:router, public formbuilder:formbuilder) {      }      ngoninit() { }      send() {          this.sending = true;         observable.timer(1000, 60)             .subscribe(() => {                 this.seconds--;             },              err => {},             () => {                 this.sending = false;                 this.seconds = 60;             });       } } 

Comments

Popular posts from this blog

amazon web services - S3 Pre-signed POST validate file type? -

c# - Check Keyboard Input Winforms -