【问题标题】:Telerik Everlive API Nativescript Angular2 SetupTelerik Everlive API Nativescript Angular2 设置
【发布时间】:2017-02-07 17:55:31
【问题描述】:

我正在尝试为我的 {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}

【问题讨论】:

    标签: angular telerik angular2-nativescript offline-mode everlive


    【解决方案1】:

    似乎everlive SDK 不知道您没有网络连接并尝试发出请求。

    用一些示例初始化代码检查这个要点 https://gist.github.com/anonymous/0d94dc664ed83004e9a349bd5f9eabd0

    【讨论】:

    • 您是在使用 Telerik 后端服务,还是有自己的 java/php 后端来获取数据?
    • telerik 后端服务
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多