Ionic framework $scope.closeModal需要什么?
这是我的代码。如果我删除关闭模态函数,就没有效果。如果单击模态外部的任何位置,模态将关闭。但我需要这个闭合模态函数,因为我需要在其中设置一个标志以供进一步使用。我如何进一步进行Ionic framework $scope.closeModal需要什么?,ionic-framework,Ionic Framework,这是我的代码。如果我删除关闭模态函数,就没有效果。如果单击模态外部的任何位置,模态将关闭。但我需要这个闭合模态函数,因为我需要在其中设置一个标志以供进一步使用。我如何进一步进行 $scope.$on('$ionicView.afterEnter', function() { $scope.openModal(); } $ionicModal.fromTemplateUrl("settings/settingsModal.html", { scope: $scope,
$scope.$on('$ionicView.afterEnter', function() {
$scope.openModal();
}
$ionicModal.fromTemplateUrl("settings/settingsModal.html", {
scope: $scope,
animation: 'slide-in-up'
}).then(function(modal) {
$scope.modal = modal;
});
$scope.openModal = function(){
$scope.modal.show();
}
$scope.closeModal = function(){
$scope.modal.hide();
};
}
关闭模式功能用于手动关闭模式的情况。例如,在一段时间后,它被打开,或者如果发生了什么事情/用户做了什么,例如按下按钮 当模态被隐藏/移除时,有适合您的情况和需要的倾听方式。例如:
// Execute action on hide modal
$scope.$on('modal.hidden', function() {
// Execute action
console.log('modal was hidden');
});
// Execute action on remove modal
$scope.$on('modal.removed', function() {
// Execute action
console.log('modal was removed');
});
有了这些,你应该能够做我理解的你想要做的事情
直接从文档:$ionicModal/在Ionic中有两种实现模式的方法。一种方法是添加单独的模板,另一种方法是将其添加到常规HTML文件顶部的脚本标记内。我们需要做的第一件事是使用角度依赖注入将模态连接到控制器。然后我们需要创建模态。我们将传入范围并将动画添加到模型中 之后,我们将创建用于打开、关闭、销毁modal的函数,最后两个函数是我们可以编写代码的地方,如果modal被隐藏或删除,这些代码将被触发。如果您不想在删除或隐藏模式时触发任何功能,可以删除最后两个功能 控制器代码:
.controller('MyController', function($scope, $ionicModal) {
$ionicModal.fromTemplateUrl('my-modal.html', {
scope: $scope,
animation: 'slide-in-up'
}).then(function(modal) {
$scope.modal = modal;
});
$scope.openModal = function() {
$scope.modal.show();
};
$scope.closeModal = function() {
$scope.modal.hide();
};
//Cleanup the modal when we're done with it!
$scope.$on('$destroy', function() {
$scope.modal.remove();
});
// Execute action on hide modal
$scope.$on('modal.hidden', function() {
// Execute action
});
// Execute action on remove modal
$scope.$on('modal.removed', function() {
// Execute action
});
});
<script id = "my-modal.html" type = "text/ng-template">
<ion-modal-view>
<ion-header-bar>
<h1 class = "title">Modal Title</h1>
</ion-header-bar>
<ion-content>
<button class = "button icon icon-left ion-ios-close-outline"
ng-click = "closeModal()">Close Modal</button>
</ion-content>
</ion-modal-view>
</script>
HTML代码:
.controller('MyController', function($scope, $ionicModal) {
$ionicModal.fromTemplateUrl('my-modal.html', {
scope: $scope,
animation: 'slide-in-up'
}).then(function(modal) {
$scope.modal = modal;
});
$scope.openModal = function() {
$scope.modal.show();
};
$scope.closeModal = function() {
$scope.modal.hide();
};
//Cleanup the modal when we're done with it!
$scope.$on('$destroy', function() {
$scope.modal.remove();
});
// Execute action on hide modal
$scope.$on('modal.hidden', function() {
// Execute action
});
// Execute action on remove modal
$scope.$on('modal.removed', function() {
// Execute action
});
});
<script id = "my-modal.html" type = "text/ng-template">
<ion-modal-view>
<ion-header-bar>
<h1 class = "title">Modal Title</h1>
</ion-header-bar>
<ion-content>
<button class = "button icon icon-left ion-ios-close-outline"
ng-click = "closeModal()">Close Modal</button>
</ion-content>
</ion-modal-view>
</script>
情态标题
闭合模态
还有其他模态优化选项。我已经演示了如何使用范围和动画。下表显示了其他选项
您想在模式关闭时从模式获取数据吗?