I have a function called
opensnack(text) { ... };
which is opening an angular material snackbar with the given text input.
What I
Angular 6 run a function in every X seconds
import { Component, OnInit } from '@angular/core';
import { Observable } from 'rxjs';
@Component({
selector: 'my-app',
template: `
Now {{time | date: 'hh:mm:ss'}}
Now {{time$ | async | date: 'hh:mm:ss'}}
`
})
export class AppComponent {
time: Date;
time$;
constructor() {
// First way: manual subscribe
Observable
.interval(1000)
.map(() => new Date())
.subscribe(res => this.time = res)
// Angular way: by using the `async` pipe
this.time$ = Observable.interval(1000).map(() => new Date())
}
}