[英]Property 'subscribe' does not exist on type '{}'
I have the following problem where I am trying to get cookies from my browser however I need to get them as they appear.我有以下问题,我试图从我的浏览器中获取 cookies 但是我需要在它们出现时获取它们。 Some of them don't appear instantly so I am trying to use the below code to get them as they come.
其中一些不会立即出现,所以我尝试使用下面的代码来获取它们。 The error I am seeing in my editor is:
我在编辑器中看到的错误是:
Property 'subscribe' does not exist on type '{}'
类型“{}”上不存在属性“订阅”
import { CookieService } from 'ngx-cookie-service';
this._cookieService.getAll().subscribe((result) => {
console.log(result);
});
Can someone please assist有人可以帮忙吗
Corresponding to the documentation the getAll function returns a map with the key value pairs.对应于文档,getAll function 返回带有键值对的 map。 So no need to subscribe to it.
所以不需要订阅它。
https://www.npmjs.com/package/ngx-cookie-service https://www.npmjs.com/package/ngx-cookie-service
var result = this._cookieService.getAll();
If you want to get notified of cookie changes you might end up writing a function that periodically checks for changes like suggested in other answers here or on other questions around: can i be notified of cookie changes in client side javascript如果您想收到有关 cookie 更改的通知,您最终可能会编写一个 function 定期检查此处其他答案中建议的更改或其他问题: 我可以在客户端收到有关 cookie 更改的通知 javascript
ngx-cookie-service doesnt provide any helper to reach that (nor does any of the other cookie helper libraries I found by a little research). ngx-cookie-service 没有提供任何帮助程序来实现这一点(我通过一点研究发现的任何其他 cookie 帮助程序库也没有)。
ngx-cookie-service
's getAll() method returns object not Observable. ngx-cookie-service
的 getAll() 方法返回 object 不可观察。
It is: getAll(): {}它是: getAll(): {}
Simply use:只需使用:
result = this._cookieService.getAll();
Check Documentation检查文档
You could write a service with a polling function based on the rxjs timer(), that checks the cookies continuously:您可以编写一个基于 rxjs timer() 轮询 function 的服务,它会持续检查 cookies:
private timer$: Subscription = new Subscription();
public polling(frequency = 1000 * 60 * 5) {
this.timer$.unsubscribe();
this.timer$ = timer(0, frequency).subscribe(
() => this.result = this._cookieService.getAll();
);
}
I hope this approach helps you!我希望这种方法对您有所帮助!
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.