小编Sur*_*iya的帖子

暂停/恢复计时器 Observable

我正在使用 angular/rxjs6 构建一个简单的秒表,我可以启动计时器,但无法暂停/恢复它。

  source: Observable<number>;
  subscribe: Subscription;

  start() {
    this.source = timer(0, 1000);
    this.subscribe = this.source
      .subscribe(number => {
        this.toSeconds = number % 60;
        this.toMinutes = Math.floor(number / 60);
        this.toHours = Math.floor(number / (60 * 60));

        this.seconds = (this.toSeconds < 10 ? '0' : '') + this.toSeconds;
        this.minutes = (this.toMinutes < 10 ? '0' : '') + this.toMinutes;
        this.hours = (this.toHours < 10 ? '0' : '') + this.toHours;
    });
  }

  pause() {
    this.subscribe.unsubscribe(); // not working
  }
Run Code Online (Sandbox Code Playgroud)

经过大量搜索后,我发现我应该使用switchMap …

angular angular6 rxjs6

7
推荐指数
1
解决办法
5863
查看次数

ng build --prod 工作不正常?如何检查?

我有一个 angular cli 应用程序。如果我使用ng serve命令运行它,它工作正常。

ng serve我没有使用,而是使用了ng build --prod. 它引发以下脚本错误:

截屏:

在此处输入图片说明

我想在生产模式下检查这个应用程序。

在这里我附上了我的代码:

import { Component, ViewChild, OnInit, ElementRef } from '@angular/core';
import { DialogComponent } from '@syncfusion/ej2-angular-popups';
import { EmitType } from '@syncfusion/ej2-base';
@Component({
  selector: 'app-root',
  templateUrl: './app.component.html',
  styleUrls: ['./app.component.css']
})
export class AppComponent {
  title="test";
  @ViewChild('ejDialog') ejDialog: DialogComponent;
  // Create element reference for dialog target element.
  @ViewChild('container', { read: ElementRef }) container: ElementRef;
  // The Dialog shows within the target element.
  public targetElement: …
Run Code Online (Sandbox Code Playgroud)

typescript angular

4
推荐指数
2
解决办法
9617
查看次数

标签 统计

angular ×2

angular6 ×1

rxjs6 ×1

typescript ×1