角度6服务人员数据组不起作用 [英] angular 6 service worker dataGroups not working

查看:38
本文介绍了角度6服务人员数据组不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试部署一个后台Service Worker,在这种情况下3s在某个时间间隔内对api进行调用,但是它似乎无法正常工作,当我转到应用程序时,我没有收到对服务器的任何请求.

Hi I am trying to deploy a background Service worker that makes calls to api in some time interval in this case 3s, but it seams not to work, when I go to application I am getting no requests to server.

我在ngsw-config.json中的数据组站立:

My data group in ngsw-config.json stands:

  "dataGroups": [
    {
      "name": "app-service-list",
      "urls": [ "http://localhost:5000/api/TcpCommunication/GetCabinsService" ],
      "cacheConfig": {
        "maxSize": 5,
        "maxAge": "3s",
        "strategy": "performance"
      }
    }
  ]

当我执行http-server -p 8090网页但未发送任何请求时,我在app.module.ts行中:

And when I do http-server -p 8090 web page works, but not sending any requests, I have in my app.module.ts line:

ServiceWorkerModule.register('/ngsw-worker.js', { enabled: environment.production })

和app.json中的

and in app.json:

在我的有角json中

"serviceWorker": true

我通过ng add @ angular/pwa @ 0.6.8将服务工作者添加到了现有的angular应用程序中

I've added that service worker to existing angular application by ng add @angular/pwa@0.6.8

那我想念什么?

推荐答案

在使用服务工作者时,它们在您的情况下充当缓存级别.这意味着它将在您配置它们时对其进行缓存或预成型.
它不会仅仅通过您的配置自行完成此操作,您实际上必须从api获取HTTP调用.您想看看官方文档中的 service-worker-communications .

When you are using the service workers, they acting in your case as a cache level. which means that it will cache or preform as you configure them to.
It won't do it by it self just from your configuration, you have to actually get the HTTP Calls from the api. You wanna take a look service-worker-communications from the official docs.

简而言之,您必须创建一个使用 SwUpdate服务 的新服务,并且在您的情况下,可能需要注册一个时间间隔,该时间间隔将从API,然后检查您的软件是否正常工作.

In short, you have to create a new service, which consume the SwUpdate service, and in your case, maybe register an interval which will get the data from the API, and check if your SW works.

这篇关于角度6服务人员数据组不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆