AngularJS does not hide the Onsen UI modal

I am new to working with angularjs and onsen ui. I have implemented a modal in an ajax request, which is supposed to hide upon successful response. Everything seems to be working fine, except for the fact that when I navigate back to the page, the modal reappears and does not hide again. Can someone please assist me in identifying where I may have gone wrong? Below is a snippet of my code:

HTML

<ons-navigator animation="slide" var="gallery">  
<ons-page style="background: #FFFFFF url('images/splash-screen.png') repeat scroll 0 0 / cover;" class="homepage">
  <ons-toolbar style="height: 120px; padding-top: 10px;">
    <div class="left">
      <ons-toolbar-button ng-click="menu.toggle()"><ons-icon icon="ion-android-menu" fixed-width="false"></ons-icon></ons-toolbar-button>
    </div>
    <div class="center">
     <img src="images/logo.png" alt="Cayman After Work" style="max-width: 130px;"/> 

        ...

</ons-page>
</ons-navigator>  

JavaScript

app.controller('menuController', function ($http, $scope, $compile, $filter, $sce)
    {
        var Start = '0';
        var Pagesize = '10';

         modal.show();

        $http({
            method: 'POST',
            url:  API_HOST+'/webservice/categorylist',
            headers: {
                'Content-Type': 'application/x-www-form-urlencoded',
                'caymanauth': caymanauth
            },
            data : "&Start=" + Start + "&Pagesize=" + Pagesize

        }).success(function ( data )
        {
           modal.hide();

            var i;
            var Content = ' ';
            var resid = ' ';
            var imglogo='';
            
            ...
            
});

//$scope.alert = function() {
//   
//};
    });

Answer №1

In order to effectively utilize modal show & hide functionality, it is recommended to define the service at a higher level as shown below:

app.factory('service') {
     return {
        showSpinnerAuto : function() {
            modal.show();
            setTimeout('modal.hide()', 10000);
        },
        showSpinnerTimer : function(timer) {
            modal.show();
            setTimeout('modal.hide()', timer);
        },
        showSpinner : function() {
            modal.show();
        },
        hideSpinner : function() {
            modal.hide();
        }
    };
});

After defining the service, make sure to include it in your controller:

app.controller('menuController', function (service, $http, $scope, $compile, $filter, $sce)

With the service now accessible in your controller, you can easily use the following commands:

service.showSpinner(); // to display a modal
service.hideSpinner(); // to hide a modal

We hope this information proves helpful!

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

How does NodeJs handle ongoing tasks and processes seamlessly?

One interesting concept is the Event Loop, which accepts callbacks and executes them as needed. As far as I understand, this operates on a single thread event loop, meaning only one callback is executed at a time. Consider the following example: setInterv ...

Ways to change attributes of deeply embedded objects?

Imagine having a complex object with nested properties like this: const obj = { Visualization: { Lower: [{ name: "Part", selectedValue: "60-000" }], Upper: [{ name: "Part", selectedValue: "60-000" }], ...

stop initial focus on input field in Ionic

One issue I'm facing is that my login screen for the application automatically focuses on the 'username' input field and triggers the keyboard to pop up. This causes the contents of the login screen to push up, resulting in incorrect dimensi ...

Unable to display Apexcharts bar chart in Vue.js application

Struggling to incorporate Apexcharts into my Vue.js site, but unfortunately, the chart isn't appearing as expected. -For more guidance on Apexcharts, check out their documentation Here HTML <div class="section sec2"> <div id="chart" ...

Encountered an error while building CSS Modules for a Vue.js project

Working on a project in Vue.js, I decided to incorporate CSS modules for my local styles (for sass and scss). However, I continuously encounter a 'Failed to compile error' related to the CSS Loader validation process. Despite attempting various ...

In AngularJS, the use of the '+' operator is causing concatenation instead of addition

Looking for assistance with my TypeScript code where I've created a basic calculator. Everything is working as expected except for addition, which seems to be concatenating the numbers instead of adding them together. HTML CODE : <input type="tex ...

jQuery DataTable error: Attempted to set property 'destroy' on an undefined object

<script> $('#archiveTable').DataTable({}); </script> <table id="archiveTable" datatable="ng" class="table table-sm" style="color:black"> <!--some code--> </table> This is a snippet of HTML code Upon checking t ...

Navigating through elements in an array in node.js

Within my array, I store the languages that users prefer. Here is an example: let language = [] var Lang = "it" language.push(Lang) This process is repeated with various languages. The array would eventually contain these values: language ...

Finding a specific object within an array of objects by searching through a key value pair

In my collection, I have an array of objects structured as follows: [{ "businessunit": [{ "Area": [{ "Asset": [{ "Wells": { "Well": "Well 11" }, "name": "Field ...

Deleting a nested object from an array within another object

Recently, I delved into the world of Redux and have found it quite fascinating. However, I am currently facing a dilemma where my new reducer function inadvertently changes the type of a state variable, which is not what I intended. The desired structure ...

How can I generate a checkbox in a database with a field that allows for enabling and disabling?

I am looking to design a table that includes questions, checkboxes, and text boxes. All the questions are stored in a database and called through an array. In addition, I want to create disabled textboxes that become enabled when their corresponding checkb ...

What sets apart AngularJs's complete $http post from its shorthand counterpart $http.post?

When sending Object data from app.js to homecontroller using two different methods (full $http.post and shorthand $http.post) as shown below: var book = { "title" : $scope.addTitle, "publisher" : $scope.publisherSelected[0], "authors" : $scope ...

Creating a personalized message for a failed "Get" request using the HTTPS native module in combination with

Currently, I have implemented an Express application that includes an HTTP GET request to an external API. It functions properly when there are no errors; however, I am looking to customize the response sent to the client-side in case of failures: const ht ...

The Express application encounters a 500 Internal Server Error due to a TypeError where the Object #<EventEmitter> does not contain the method 'hr

The staging instance of my webapp is encountering an issue: Express 500 TypeError: Object #<EventEmitter> has no method 'hrtime' at Object.logger [as handle] (F:\approot\node_modules\express\node_modules\connect ...

What's the secret behind generating a crisp 400 on paper?

Understanding Why it Prints 400 I'm struggling to comprehend the logic behind this var x = {}, y = { key: "y" }, z = { key: "z" }; x[y] = 100; x[z] = 200; console.log(x[y] + x[z]); ...

Using Javascript's .replace() method to preserve HTML elements

This is a JavaScript function I wrote function replaceCharacters(text_input){ return text_input .replace(/O/g, 0) .replace(/I/g, 1) .replace(/o/g, 0) .replace(/i/g, 1) .replace(/t/g, 4) .replace(/d/g, 9) ...

How can the executable path for Firefox be specified in Nightwatch?

I've been using nightwatch to run tests on both Chrome and Firefox with great success. While everything runs smoothly on Chrome, I'm facing an issue when trying to run tests on Firefox on my personal machine. Currently, due to Marionette's ...

React is generating an error when attempting to use hooks without the appropriate class name prefix

I'm encountering an error when I use hooks without a class name prefix. Can someone help me troubleshoot this issue? import React, {Fragment,useState} from 'react'; function App (props) { const [x,updateX] = useState(1) /* throwing error ...

The enigmatic jQuery AJAX glitch is craving additional arguments

My website uses jQuery's ajax function to handle user signups. Despite using similar code throughout the site, I encountered an error while trying to execute the code below: Error Message: uncaught exception: [Exception... "Not enough arguments" nsr ...

Arranging unrelated divs in alignment

http://codepen.io/anon/pen/Gxbfu <-- Here is the specific portion of the website that needs alignment. My goal is to have Onyx Design perfectly aligned with the right side of the navbar, or to have the navbar extend up to the end of "Onyx Design". The ...