Why won't my div tag show conditionally with AngularJS ng-show?

I'm having trouble displaying a div tag on a form based on the boolean flag specified in ng-show. Unfortunately, the div is not showing up at all. Here's what I've tried so far without success. Any assistance would be greatly appreciated!

Form control in MVC View:

<form name="payment" role="form" ng-submit="sendPayment()" ng-controller="PaymentCtrl">
        <div id="veil" ng-show="isProcessing == true"></div>
        <div id="feedLoading" ng-show="isProcessing == true">
            <img src="~/images/ajax_loader_blue_64.gif" class="img-responsive center-block" />
        </div>

        //Other form controls here
</form>

In Angular controller: This controller is the same as the one being used by the form, which is "PaymentCtrl".

$scope.isProcessing = false;

    $scope.setProcessing = function (loading) {
        $scope.isProcessing = loading;
    }

    $scope.sendPayment = function () {
        $scope.setProcessing(true);
        //Other logic here
        $scope.setProcessing(false);
    };

CSS Styles for div tags:

#veil {
position: absolute;
top: 0;
left: 0;
height:100%;
width:100%;
cursor: not-allowed;
filter: alpha(opacity=60);
opacity: 0.6;
background: #000000 url(http://www.wingo.com/angular/AngularShieldLogo.png) no-repeat center;
}

#feedLoading {
position: absolute;
top:200px;
width:100%;
text-align: center;
font-size: 4em;
color:white;
text-shadow: 2px 2px 2px #021124;
}

Answer №1

It is likely that your sendPayment function is initiating an asynchronous service call which relies on a promise to be resolved. The boolean isProcessing within your code is being toggled back immediately at the end of the function's execution. This means that regardless of when the promise resolves, the boolean has already been changed.

To address this issue, it is recommended to reset the isProcessing boolean after the promise has returned. Ensure that you reset it within both the success and error callback functions. For instance, if your code involves a promise:

service.sendPayment() 
    .then(function() {
            $scope.setProcessing(false);
        },
        function(error) {
            $scope.setProcessing(false);
        });

Alternatively, if you are utilizing $http within your controller, you can utilize the encapsulated .success and .error callbacks:

$http.post(url, data) 
    .success(function () {
        $scope.setProcessing(false);
    })
    .error(function (error) {
        $scope.setProcessing(false);
    });

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

Using the scroll feature in the selectyze plugin allows for smooth

The jQuery plugin selectyze from https://github.com/alpixel/Selectyze serves to replace the standard selectbox (dropdown), but there is a small issue that can be quite irritating. I am hoping someone out there may have a solution. Annoying Situation Here ...

How to store data retrieved with $http.get in AngularJS into a variable

I am attempting to assign data retrieved from $http.get to a variable in my controller. $http.get(URL).success(function (data) { $scope.results = data; console.log('results within $http.get :'+ $scope.results); }); console.lo ...

Difficulty encountered with document.querySelectorAll retrieving paginated elements

I am currently developing a project called STEEP. Our implementation involves utilizing infinite scroll to load 8 videos at a time as the user scrolls through the page. However, we are facing an issue with the script responsible for handling video playbac ...

The mat-datepicker appears in a unique location each time it is opened

I am facing an issue with my mat-datepicker appearing in the opposite place when clicked on one component. How can I resolve this? I have two different components with mat-datepicker, but they behave differently. I suspect that imitating a click in one com ...

What is the best way to link the value of a mat-slider to an input field in a reactive form?

Is there a way to synchronize the min and max values of a ranged mat-slider with corresponding input fields? Currently, when I set numbers in the input fields, the slider updates correctly. However, when I use the slider to change the value of the input fi ...

Formik's handleSubmit function seems to be being overlooked and not executed as

I've encountered an issue while trying to validate a form before submission using formik and yup validation. The form is divided into two parts, where the first part needs to be validated before moving on to the second part. I set a state handleShow(t ...

Navigating the Foundation Topbar - Should I Toggle?

Is there a simpler way to achieve the navigation I desire, similar to the switcher for uikit? Instead of using data-toggler on each tag in my top bar, is there an easier method where I can click links in my top bar to display different content without go ...

I am facing an issue with uploading files to my designated directory through Node.js Multer

After creating a web service using node js and implementing a form with React interface that includes user information and file upload, I encountered an issue while attempting to save the file to the specified directory on the node js server using multer. ...

Creating a Border Length Animation Effect for Button Hover in Material-UI

I'm currently exploring Material-UI and trying to customize a component. My goal is to add a 'Border Length Animation' effect when hovering over the button. Unfortunately, I have yet to successfully implement this animation as intended. For ...

Is it possible to scroll a div on mobile without the need for jQuery plugins?

Upon investigating the initial query, we managed to implement D3js for identifying a scroll event. This allowed us to scroll the div #scroll-content from any location on desktop devices. However, we encountered an issue where this method does not function ...

Enhance communication system by optimizing MySQL, JavaScript, and PHP chat functionality

I have created a chat application using Javascript, PHP, and MySQL for two users. Every 3 seconds, it makes an AJAX request to a PHP file to retrieve messages from the database and update the page. Currently, the PHP query used is: SELECT * FROM tmessages ...

Click on the form to initiate when the action is set to "javascript:void(0)"

I am working on an HTML step form that needs to be submitted after passing validation and ensuring all fields are filled. The form currently has an action controller called register.php, but also includes action="javascript:void(0);" in the HTML form. What ...

Delete JavaScript functions and events from memory once the JavaScript code has been removed from the HTML file

I am encountering a situation with my website where popups loaded via ajax also load JavaScript code, which I want to remove when the popup is closed. The main site code looks like this: <body> ... <div id="popup" style="display:none"> < ...

Implementing Canvas Offset in a jQuery Mobile Environment

I have positioned a pen ready for use at this location. http://codepen.io/prantikv/pen/LEbRKY Currently, I am utilizing a canvas to track mouse movements or touch input. It performs as expected when jQuery or jQuery mobile is not included. However, upon ...

Rendering React.js components as children of DOM elements

Trying my hand at creating a custom Map component includes the task of designing a unique Map Annotation. Here's an example of how a MapAnnotation component appears in the render function: <MapAnnotation title='Annotation' latitude={ 12.3 ...

Displaying both the key and value in a filter list using Angular 1.6's ng-switch

I am currently working on creating a conditional filter for a list of products. Everything was running smoothly until I made changes to the product model to support multiple categories. After this modification, the filter stopped working and an error was d ...

Is it possible to resend an AJAX request using a hyperlink?

Is it possible to refresh only the AJAX request and update the content fetched from an external site in the code provided below? $(document).ready(function () { var mySearch = $('input#id_search').quicksearch('#content table', ...

The data in Node AngularJS is not loading upon the page's initial load

When I log in, I am redirected to a different page where a partial page is loaded using an AngularJS route. By clicking on any anchor tag, the respective partial view is displayed. However, I encountered an issue. Upon logging in, I use res.render(pagenam ...

Is there a way to upload a kml file to Google Maps using my website or by using JavaScript commands?

I have information on my website regarding gas stations, including the quality of gasoline and the GPS coordinates of each station. My concept involves incorporating Google Maps into my site, similar to how flightradar24.com displays pins indicating gas s ...

Prevent the execution of a post request function depending on the promise result?

When I handle a POST request in express, I am required to retrieve data from a mongoDB cluster and then respond accordingly based on the retrieved response. app.post('/api/persons', (req, res) => { const data = req.body; if (!data.name || ...