[英]Angular 9 PWA with Carousel and Service worker does not get registered
Hey guys this is a bit weird situation,嘿伙计们,这是一个有点奇怪的情况,
First I use Angular 9 with Bootstrap 3.3.5 (cannot update to latest yet),首先,我使用 Angular 9 和 Bootstrap 3.3.5(还不能更新到最新版本),
on the homepage I have the Carousel and it I have implemented angular PWA also.在主页上我有 Carousel,我也实现了 angular PWA。
Problem is if I use PWA and carousel, Serviceworker(SW) does not get regitered.问题是如果我使用 PWA 和轮播,Serviceworker(SW) 不会被重新注册。 If I commented out the carousel code it does.
如果我注释掉它的轮播代码。 If I commented Jquery it get registered because then carousel does not work.
如果我评论 Jquery 它会被注册,因为这样轮播不起作用。 And same thing happen with ngx-owl-carousel also,
同样的事情也发生在ngx-owl-carousel上,
I do not have any solution here.我这里没有任何解决方案。 If you can provide any kinds of hints or solutions it will be a big help.
如果您可以提供任何类型的提示或解决方案,那将是一个很大的帮助。 Thanks:) Interesting find is that when I click on the carousel sometimes service worker gets registered somehow.
谢谢:) 有趣的发现是,当我单击轮播时,有时服务人员会以某种方式注册。 -_- anyway this is my code for the carousel,
-_- 无论如何,这是我的轮播代码,
<div class="bloc bgc-white full-width-bloc l-bloc" id="bloc-2">
<div class="container">
<div class="row row-no-gutters">
<div class="col-sm-12">
<div id="carousel-1" class="carousel no-shadows slide" data-ride="carousel">
<div class="carousel-inner" role="listbox">
<div class="item active">
<img [attr.src]="sliderData[0].sliderImgUrl" (click)="navigateSliderProd('product',sliderData[0])" (load)="imageLoaded($event)"/>
</div>
<div class="item" *ngFor="let slider of sliderData | slice:1;let i = index">
<img [attr.src]="slider.sliderImgUrl" (click)="navigateSliderProd('product',sliderData[i+1])" (load)="imageLoaded($event)"/>
</div>
</div>
<a class="left carousel-control" href="#carousel-1" role="button" data-slide="prev">
<span class="fa fa-chevron-left"></span><span class="sr-only">Previous</span>
</a>
<a class="right carousel-control" href="#carousel-1" role="button" data-slide="next">
<span class="fa fa-chevron-right"></span><span class="sr-only">Next</span>
</a>
</div>
</div>
</div>
</div>
</div>
Set the ServiceWorkerModule
registrationStrategy
to registerImmediately
(or registerWithDelay
).将
ServiceWorkerModule
registrationStrategy
设置为registerImmediately
(或registerWithDelay
)。 By default SW registration waits until the app is stable (no outstanding microtasks or macrotasks).默认情况下,软件注册等到应用程序稳定(没有未完成的微任务或宏任务)。 A
setTimeout
, which is common in carousels, will cause the app to never be stable.轮播中常见的
setTimeout
会导致应用程序永远不稳定。
ServiceWorkerModule.register('ngsw-worker.js', {
enabled: environment.production,
registrationStrategy: 'registerImmediately',
}),
Note that Angular is making this unnecessary by registering after 30 seconds if still unstable.请注意,Angular 如果仍然不稳定,则在 30 秒后注册,从而使此操作变得不必要。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.