如何在AngularJS应用程序开始时显示IonicModel?
如何在应用程序启动时显示IonicModel?这个代码不起作用如何在AngularJS应用程序开始时显示IonicModel?,angularjs,ionic-framework,ionic,Angularjs,Ionic Framework,Ionic,如何在应用程序启动时显示IonicModel?这个代码不起作用 angular.module('testApp', ['ionic']) .controller('MyController', function($scope, $ionicModal, $ionicPlatform) { $ionicPlatform.ready(function(){ $scope.initApp = function() { // some init variables here
angular.module('testApp', ['ionic'])
.controller('MyController', function($scope, $ionicModal, $ionicPlatform) {
$ionicPlatform.ready(function(){
$scope.initApp = function() {
// some init variables here
if (someVariable){
$scope.openModal();
}
}
// init ionicModal here
$scope.openModal = function() {
$scope.modal.show();
};
$scope.initApp();
});
});
但是这项工作
angular.module('testApp', ['ionic'])
.controller('MyController', function($scope, $ionicModal, $ionicPlatform, $timeout) {
$ionicPlatform.ready(function(){
$scope.initApp = function() {
// some init variables here
if (someVariable){
$timeout(function() {
$scope.openModal();
}, 1000);
}
}
// init Modal here
$scope.openModal = function() {
$scope.modal.show();
};
$scope.initApp();
});
});
我想在应用程序启动时立即打开模式窗口。我该怎么做?谢谢
编辑代码您应该等到设备准备就绪,有很多方法可以使用,下面是我找到的一种方法:
$ionicPlatform.ready(function() {
$scope.openModal();
});
据我所知,应用程序在设备准备就绪时启动 因此,您可以使用$ionicPlatform.ready方法在设备准备就绪时附加回调 一旦设备准备就绪,或者如果设备已准备就绪,则立即触发回调
用新代码编辑我的问题。它也不起作用。是的!I传输ionicPlatform.ready(函数(){});到$scope.initApp();现在,应用程序正在正确启动。非常感谢。
angular.module('testApp', ['ionic'])
.controller('MyController', function($scope, $ionicModal, $ionicPlatform) {
$ionicModal.fromTemplateUrl('my-modal.html', {
scope: $scope,
animation: 'slide-in-up'
}).then(function(modal) {
$scope.modal = modal;
});
$scope.openModal = function() {
$scope.modal.show();
};
$ionicPlatform.ready(function(){
$scope.openModal();
});
});