离子运行时错误无法读取null的属性“ toLowerCase”

时间:2018-07-07 17:16:27

标签: ionic-framework runtime

我正在尝试通过“离子服务”查看应用程序,但出现此错误。我看过其他主题,但从未见过运行时错误。我尝试了所有的解决方案,但仍然会有相同的错误页面。这是我看到的:

https://i.stack.imgur.com/hQi3o.jpg

说实话,我不是这个应用的编码员,但我是从商店购买的。但是,我在这里和那里知道一些。如果有解决此问题的简单方法,那就太好了!

第一个错误链接指向此处:

    httpGet = (options) => {
    return new Promise((resolve, reject) => {
        resolve(/*return your result here*/);
        reject(/*return error here*/);
    });
}


//inside of some function
let firstResult, secondResult;
httpGet(argument)
    .then(result => {
        firstResult = result;
        //you can chain promise if u need
        return httpGet(secondArgument)
    })
    .then(result => {
        secondResult = result;
    })
    .then(() => {
        //here you can acces firstResult, secondResult variables, pass them to some function as arguments
    })
    .catch((error)=>{})

第二个错误链接将我指向此处:

_this.initialData();
var operating_system = '';
var admob = {};
if (_this.device.platform.toLowerCase() == 'android') {
     operating_system = 'android';
     admob = {
         banner: settings['admob_android_banner'],
         interstitial: settings['admob_android_interstitial']
     };
 }

第三个错误指向这里:

SafeSubscriber.prototype.__tryOrUnsub = function (fn, value) {
    try {
        fn.call(this._context, value);
    }
    catch (err) {
        this.unsubscribe();
        throw err;
    }
};

第四个错误指向这里:

SafeSubscriber.prototype.next = function (value) {
    if (!this.isStopped && this._next) {
        var _parentSubscriber = this._parentSubscriber;
        if (!_parentSubscriber.syncErrorThrowable) {
            this.__tryOrUnsub(this._next, value);
        }
        else if (this.__tryOrSetError(_parentSubscriber, this._next, value)) {
            this.unsubscribe();
        }
    }

第五个错误指向此处:

Subscriber.prototype._next = function (value) {
    this.destination.next(value);
};

这是我在cmd中获得的代码:

var /** @type {?} */ response = new Response(responseOptions);
    response.ok = isSuccess(status);
        if (response.ok) {
            responseObserver.next(response);
            // TODO(gdi2290): defer complete if array buffer until done
            responseObserver.complete();
            return;
        }

2 个答案:

答案 0 :(得分:0)

似乎平台未正确返回,这就是为什么它为空的原因。

您没有包括构造函数,所以我不知道您的构造函数是什么样子,但是下面的代码片段使用您在代码中使用的Device plugin正确返回了平台名称。

import { Device } from '@ionic-native/device';

constructor(private device: Device) {}

......

if(this.device.platform.toLowerCase()=='android'){
    // Your logic here
}

答案 1 :(得分:0)

发生这种情况是因为您正在网上运行离子服务,而Cordova平台在那里不可用。当属性不存在时(当cordova不可用时),Ionic Native将返回{},并且会抛出控制台警告以帮助开发人员。 当尝试从{}对象检索数据时,它将返回null。
请尝试添加以下代码:

import { Platform } from 'ionic-angular';

//add it in constructor as follows:
constructor( public platform: Platform){

}
//add platform check
if (this.platform.is('cordova')) {
   //add your code here
}else{
   console.log("Plugin not supported on web");
}
相关问题