问题描述
我有一个 angular 应用程序,并且在我的 app.component 中包含了一个 update.component。在这个组件中,我实现了一个服务工作者。它看起来像这样:
import { OnInit,Component } from '@angular/core';
import { SwUpdate } from '@angular/service-worker';
import { interval } from 'rxjs';
@Component({
selector: 'update-component',templateUrl: 'update-component.html'
})
export class UpdateComponent implements OnInit {
constructor(
public update: SwUpdate,) {}
currentVersion: string;
availabLeversion: string;
ngOnInit() {
this.initUpdate();
this.checkUpdate();
}
initUpdate() {
if(this.update.isEnabled) {
this.update.available.subscribe((event) => {
var r = confirm("Do you want to update your app?");
if (r == true) {
this.updateApp();
}
})
}
}
updateApp() {
this.update.activateUpdate().then(() => document.location.reload());
}
checkUpdate() {
const timeInterval = interval(10 * 1000);
timeInterval.subscribe(() => {
this.update.checkForUpdate()
});
}
}
因此,如果我用新版本替换当前的 angular 版本,我的应用程序会询问用户是否要更新。如果是,页面将使用新版本的应用程序刷新。如果用户单击取消,则没有任何反应。到目前为止一切顺利。
但如果用户点击取消然后刷新页面,应用程序仍然会更新。这是默认行为吗?如果是这样,我应该配置什么才能让我的用户有机会不更新?
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)