[英]How can I call a angular JavaScript function inside a cordova function
我試圖獲取一個返回true或false的函數,或者看看是否可以在此函數內調用另一個函數。
checkLocationIsOn() { cordova.plugins.diagnostic.isGpsLocationEnabled(function(enabled) { console.log('GPS location is ' + (enabled ? 'enabled' : 'disabled')); }, function(error) { console.error('The following error occurred: ' + error); } ); // tslint:disable-next-line: max-line-length cordova.plugins.locationAccuracy.request(this.onRequestSuccess, this.onRequestFailure, cordova.plugins.locationAccuracy.REQUEST_PRIORITY_HIGH_ACCURACY); }
您丟失了上下文,有兩種方法:
bind(this)
兩種方法的示例:
cordova.plugins.locationAccuracy.request(data => this.onRequestSuccess(data), this.onRequestFailure.bind(this), cordova.plugins.locationAccuracy.REQUEST_PRIORITY_HIGH_ACCURACY);
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.