How to open up an Ionic Modal upon click?

后端 未结 2 805
礼貌的吻别
礼貌的吻别 2021-02-08 22:37

I am new to Ionic and AugularJS and I am having a problem opening up a modal box upon click on a checkbox/radio button on the third option for hashtag search in the settings pag

2条回答
  •  再見小時候
    2021-02-08 23:26

    ionic modal has nothing to do with routes.

    You just load a static html template from server, and that same html is shown in ionic modal with all the bindings.

    Instead of declaring a seperate controller, move it inside the same controller :

    app.controller('hashtagController', ['$scope', function($scope, $ionicModal) {
        $scope.hashtag = function() {
            $scope.hashtagValue = 'blackandwhitephotography'; // if selected, it'll display this value
    
            $ionicModal.fromTemplateUrl('hashtag-modal.html', {
                scope: $scope,
                animation: 'slide-in-up',
                focusFirstInput: true
            }).then(function(modal) {
                $scope.modal = modal;
                $scope.modal.show();
            }); 
        };
    
        $scope.openModal = function() {
            $scope.modal.show();
        };
    
        $scope.closeModal = function() {
            $scope.modal.hide();
        };
    
    
        $scope.$on('$destroy', function() {
            $scope.modal.remove();
        });
    
        $scope.$on('modal.hidden', function() {
            // Execute action
        });
    
        $scope.$on('modal.removed', function() {
            // Execute action
        });
    }
    

    Then in your HTML :

        
    

提交回复
热议问题