android - 在 InAppBrowser Ionic 中加载 Spinner

标签 android angularjs cordova ionic-framework

我正在尝试在页面加载时在 InAppBrowser 中实现 IonicLoading Spinner。 这就是我正在做的:

<button class="button" ng-controller="View" ng-click="showHelp('http://www.google.com')">
</button>

Controller :

.controller('View', function($scope, $ionicLoading) {

	$scope.showHelp=function(url) {
	var ref = window.open(url, '_blank', 'location=yes');
    ref.addEventListener('loadstart', function(){ $ionicLoading.show(); }); 
	ref.addEventListener('loadstop', function() { $ionicLoading.hide(); });
	
	}
})

问题是微调器没有加载到 InAppBrowser 中,而是显示在后台(即仅当我关闭 InAppBrowser 时才可见)

如有任何帮助,我们将不胜感激。

最佳答案

我正在使用 ionic V2+ (ionic 3 ) 应用程序并且我使用了 cordova-plugin-dialogs 但它没有像我预期的那样为我工作。我用了Spinner Dialog并且工作得很好。请在下面找到示例代码

正在安装插件

ionic cordova 插件添加 cordova-plugin-native-spinner

npm install --save @ionic-native/spinner-dialog

代码

import { InAppBrowser } from '@ionic-native/in-app-browser';
import { SpinnerDialog } from '@ionic-native/spinner-dialog';

constructor(
private iab: InAppBrowser,
private spinnerDialog: SpinnerDialog) { }

...

 const browser = this.iab.create('https://www.google.com',
  '_blank',
  {
    location: 'no',
    clearcache: 'yes',
    clearsessioncache: 'yes'
  });

browser.on('loadstart').subscribe((eve) => {
  this.spinnerDialog.show(null, null, true);     
}, err => {
  this.spinnerDialog.hide();
})

browser.on('loadstop').subscribe(()=>{
  this.spinnerDialog.hide();
}, err =>{
  this.spinnerDialog.hide();
})

browser.on('loaderror').subscribe(()=>{
  this.spinnerDialog.hide();
}, err =>{
  this.spinnerDialog.hide();
})

browser.on('exit').subscribe(()=>{
  this.spinnerDialog.hide();
}, err =>{
  this.spinnerDialog.hide();
})

关于android - 在 InAppBrowser Ionic 中加载 Spinner,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37836963/

相关文章:

android - 如何使用 FFmpeg for android 编译 OpenCV 4.4?

Android - 仅启用 URL 链接,但在触及 TextView 中的非 URL 链接时禁用其他链接

javascript - angularjs仅过滤需要的短信

javascript - Angular : Filter sub-content in ng-repeat

android - 在phonegap中获取设备绝对路径?

javax.net.ssl.SSLPeerUnverifiedException : Hostname not verified:

javascript - 通过 id AngularJS 设置焦点

cordova - 安卓开发者工具 : exclude asset files (php) from apk build

audio - 在Phonegap中播放音频不起作用

android - 仅在应用程序首次启动时用于教程的 ViewPager