我正在尝试为我的 {N} ng2 应用程序设置 everlive api,并且我进行了以下设置
const Everlive = require('./utils/everlive.all');
@Component({
selector: "main",
template: "<page-router-outlet></page-router-outlet>"
})
export class AppComponent implements AfterViewInit {
el: any;
constructor(private utils: Utils) { }
ngAfterViewInit() {
this.el = new Everlive({
appId: Config.telerikAppId,
offlineStorage: true,
offline: {
syncUnmodified: true,
typeSettings: {
"ContentTypeName": {
"autoGenerateId": false
}
},
storage: {
provider: Everlive.Constants.StorageProvider.FileSystem
}
},
syncStart: this.startSync,
syncEnd: this.endSync
});
// start
this.el.online();
// track
connectivity.startMonitoring((newConnectionType: number) => {
switch (newConnectionType) {
case connectivity.connectionType.none:
console.log("Connection type changed to none.");
this.goOffline();
break;
case connectivity.connectionType.wifi:
console.log("Connection type changed to WiFi.");
this.goOnline();
break;
case connectivity.connectionType.mobile:
console.log("Connection type changed to mobile.");
this.goOnline();
break;
}
});
}
startSync() {
this.utils.showLoader();
};
endSync(syncInfo) {
this.utils.hideLoader();
alert('Sync with server complete');
console.log(syncInfo);
};
goOffline() {
this.utils.confirmBox('No internet connection, switch to offline mode?', '', 'Yes', 'No')
.then((result) => {
if (result) {
this.el.offline();
} else {
this.logout();
}
});
}
goOnline() {
this.utils.confirmBox('Internet connection detected, switch to online mode and sync data?', '', 'Yes', 'No')
.then((result) => {
if (result) {
this.utils.showLoader();
this.el.online();
this.el.sync();
} else {
this.logout();
}
});
}
logout() {
}
}
当我启动应用程序时,在一堆状态之间导航,希望数据被缓存。现在,我关闭了笔记本电脑上的 WiFi,希望它能从它缓存的文件系统中提取数据,但我看到了一个错误zone.js
Unhandled Promise rejection: Response {_body: Error: The Internet connection appears to be offline., status: 200, ok: true, statusText: "", headers: Headers…} ; Zone: <root> ; Task: Promise.then ; Value: Response {_body: Error: The Internet connection appears to be offline., status: 200, ok: true, statusText: "", headers: Headers…} undefined
这是我在sync
完成后记录响应时看到的
Object {syncedItems: undefined, syncedToServer: 0, syncedToClient: 0, failedItems: undefined, error: undefined}