如何在几秒钟内获得cookie到期的时间?

时间:2018-02-12 09:57:08

标签: javascript angularjs angular

我设置了2分钟到期时间的Cookie。 我想在HTML上显示倒计时,剩下多少秒才能使角度为2的特定cookie到期。

1 个答案:

答案 0 :(得分:0)

你可以使用

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

相关问题