我正在尝试在页面加载时在InAppBrowser中实现IonicLoading Spinner。 这就是我在做的事情:
<button class="button" ng-controller="View" ng-click="showHelp('http://www.google.com')">
</button>
控制器:
.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时才可见)
任何帮助都将不胜感激。
答案 0 :(得分:4)
我正在使用离子V2 +(离子3)应用程序,我使用cordova-plugin-dialogs
,但它并不像我预期的那样对我有效。我使用Spinner Dialog并且效果很好。请在下面找到示例代码
安装插件
ionic cordova plugin add 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();
})
答案 1 :(得分:3)
由于inAppBrowser
位于WebView
之上,因此您无法使用HTML添加Loader
。您可以在添加cordova-plugin-dialogs
插件后添加本机Loader。以下是一些可以帮助您入门的代码:
开始加载:
navigator.notification.activityStart("Please Wait", "Its loading.....");
停止加载程序:
navigator.notification.activityStop();
如果您需要更多信息,请查看this参考。
答案 2 :(得分:0)
不推荐使用<nav class="navbar navbar-expand-lg navbar-dark bg-dark">
<!-- begin flexbox containing brand and toggler -->
<div class="d-flex flex-nowrap w-100">
<a class="text-truncate navbar-brand" href="#">Very long navbar brand text that will ultimately need to be clipped with ellipsis on smaller screens than a 4K TV</a>
<button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarSupportedContent" aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
</button>
</div>
<!-- end flexbox containing brand and toggler -->
<div class="collapse navbar-collapse" id="navbarSupportedContent">
<ul class="navbar-nav mr-auto">
<li class="nav-item active">
<a class="nav-link" href="#">Home <span class="sr-only">(current)</span></a>
</li>
<li class="nav-item">
<a class="nav-link" href="#">Link</a>
</li>
<li class="nav-item dropdown">
<a class="nav-link dropdown-toggle" href="#" id="navbarDropdown" role="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
Dropdown
</a>
<div class="dropdown-menu" aria-labelledby="navbarDropdown">
<a class="dropdown-item" href="#">Action</a>
<a class="dropdown-item" href="#">Another action</a>
<div class="dropdown-divider"></div>
<a class="dropdown-item" href="#">Something else here</a>
</div>
</li>
<li class="nav-item">
<a class="nav-link disabled" href="#" tabindex="-1" aria-disabled="true">Disabled</a>
</li>
</ul>
</div>
</nav>
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.5.0/css/bootstrap.min.css" integrity="sha384-9aIt2nRpC12Uk9gS9baDl411NQApFmC26EwAOH8WgZl5MYYxFfc+NcPb1dKGj7Sk" crossorigin="anonymous">
<!-- JS, Popper.js, and jQuery -->
<script src="https://code.jquery.com/jquery-3.5.1.slim.min.js" integrity="sha384-DfXdz2htPH0lsSSs5nCTpuj/zy4C+OGpamoFVy38MVBnE+IbbVYUew+OrCXaRkfj" crossorigin="anonymous"></script>
<script src="https://cdn.jsdelivr.net/npm/popper.js@1.16.0/dist/umd/popper.min.js" integrity="sha384-Q6E9RHvbIyZFJoft+2mJbHaEWldlvI9IOYy5n3zV9zzTtmI3UksdQRVvoxMfooAo" crossorigin="anonymous"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.5.0/js/bootstrap.min.js" integrity="sha384-OgVRvuATP1z7JjHLkuOU7Xw704+h835Lr+6QL9UvYjZE3Ipu6Tp75j7Bh/kR0JKI" crossorigin="anonymous"></script>
,我建议采用以下方法来防止InAppBrowser的空白打开屏幕
以隐藏模式打开InAppBrowser,稍后在activityStop
事件中显示InAppBrowser。直到您可以显示离子装载机或您的自定义装载机
loadstop