【发布时间】:2018-02-12 09:57:07
【问题描述】:
我设置了 2 分钟过期时间的 cookie。 我想在 HTML 上显示倒计时,角度 2 中的特定 cookie 过期还剩多少秒。
【问题讨论】:
标签: javascript angularjs angular
我设置了 2 分钟过期时间的 cookie。 我想在 HTML 上显示倒计时,角度 2 中的特定 cookie 过期还剩多少秒。
【问题讨论】:
标签: javascript angularjs angular
你可以使用
import { timer } from 'rxjs/observable/timer';
import { take, map } from 'rxjs/operators';
@Component({
selector: 'my-app',
template: `<h2>{{countDown | async}}</h2>`
})
export class App {
countDown;
count = 60;
constructor() {
this.countDown = timer(0,1000).pipe(
take(this.count),
map(()=> --this.count)
);
}
}
所以在设置 cookie 时间时,您也可以在计时器中设置相同的时间。确保您分配您的 cookie 时间和此计时器时间相同的确切工作。
工作示例是here
【讨论】: