每30秒如何观察到刷新一次?

时间:2018-11-27 13:07:55

标签: angular typescript firebase observable angularfire

     style={{
          height: 100%, 
          width: "1",
          backgroundColor: "#CEDCCE",
        }}

我在Firebase中的图像每30秒就会覆盖一次。如何每30秒获取@Component({ selector: 'app-geo', templateUrl: <img mat-card-image [src]="profileUrl | async "> export class GeoComponent implements OnInit { date; profileUrl: Observable<string>; constructor(private tempService: TemperatureService, private humService: HumiditeService, public authService: AuthService,private database: AngularFireDatabase, private storage: AngularFireStorage,private router: Router) { const ref = this.storage.ref('live/live.jpg'); this.profileUrl = ref.getDownloadURL(); } } }) 的值并将其保存到Firebase?

我如何使用计时器每30秒刷新一次我的观测值?

1 个答案:

答案 0 :(得分:2)

RxJS IntervalTakeWhile运算符的组合将完成这项工作。

类似StackBlitz project example code的东西:

const source = interval(30000).pipe(
  takeWhile(() => { return true }) // here you can have some logic to stop the requests
);
const subscription = source.subscribe(
  (x) => {
    // your code goes here
  },
  function (err) {
    console.log('Error: ' + err);
  },
  function () {
    console.log('Completed');
  });