Modification to the scope are not being displayed accurately on the modal user interface

I have a disabled button that needs to be enabled after a certain amount of time.

My attempt at using $timeout and ng-disabled is not producing the desired result.

Here is the HTML code:

<button id="resend_button" class="btn btn-block btn-info" ng-click="reenviar_confirmacao()" ng-disabled="!buttonEnabled">{{'RESEND-CONFIRMATION' | translate}}</button>

Modal opening function:

ngDialog.open({
    id: 'confirmation',
    template: '../../../templates/confirmacao-sms.html',
    preCloseCallback: callback,
    backdrop  : 'static',
    keyboard  : false,
    scope: $scope
});

The function to enable the button:

$timeout(function(){
    console.log(angular.element("#resend_button"));
    // Attempted this but didn't work either
    angular.element("#resend_button").removeAttr('disabled');

    $scope.buttonEnabled = true;
    $scope.$apply();
}, 2000)

Although it updates the $scope.buttonEnblaed value, the button status only refreshes when the modal is closed and reopened.

Answer №1

Ensure the timeout is placed within the $scope.$apply block

$scope.$apply(function(){

    $timeout(function(){
        console.log(angular.element("#resend_button"));
        // Attempted this without success
        angular.element("#resend_button").removeAttr('disabled');

        $scope.buttonEnabled = true;

    }, 2000)

});

Answer №2

The solution was removing one of the redundant ng-controller instances, which resolved the issue.

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

Retrieve a particular item from an array of JSON objects

My services.js file is structured like this: var app = angular.module('starter.services', []) .factory('Studies',function($http,$filter){ var studies = []; $http.get("studies.json").success( f ...

Use ajax request to serialize input into HTML value

I implemented a jquery.ajax post request to send data to the server using C#, however, I encountered an error with my code. Here is the code snippet: $(function(){ $('#frmSubmit').on('submit', function(e){ e.preventDefault(); ...

Encountering a NextJS error with head component

Trying to incorporate the head element into a NextJS page format has proven challenging. Despite consulting the official documentation, implementing next/head to add <head> has resulted in an error within the code block. Code: import Head from &apos ...

What is the best way to implement a directive that will reset the selected value in a dropdown menu

I have created a custom tab control with a dropdown menu of colors for each tab. I am looking to reset the color selection in all tabs simultaneously. The directive I am currently using is: <button class="btn btn-warning" ng-click="colors=' ' ...

Navbar remains visible despite ng-hide directive

I am having issues hiding a navbar based on the user's login status. Despite changing the $scope.loggedIn variable, the navbar does not hide as expected. Why is this happening? View: <nav> <div ng-controller="mainCtrl"> <!-- Lo ...

The parsing of source maps fails due to issues with the .htaccess file

After analyzing the web page, I found that the .htaccess file contains the following code: RewriteEngine On RewriteBase / Options -MultiViews DirectorySlash Off # skip POST requests RewriteCond %{REQUEST_METHOD} POST RewriteRule ^ - [L] RewriteCond %{R ...

Navigating tables with jQuery using a loop and extracting data from two tables with matching row names

I am facing a challenge with a function that combines data from two tables, each containing a column named "name". How can I specify which table's name should be displayed? function createTableRow(customers) { var data = JSON.parse(customers.resu ...

Issue with texture visibility in ThreeJS: Texture appears in debug mode but not in regular display mode

Currently delving into ThreeJS and JavaScript, I am in the process of constructing a scene with 2 meshes: A cube positioned at the origin. A "floor" situated on the XY plane, utilizing a checkered texture loaded from an image. When running it in debug mo ...

Is there a way to direct to a specific URL upon clicking a button using PHP?

In my PHP code called registerprocess.php, it executes after clicking a submit button on another page named userregistration.php. If a user tries to register with an email that already exists in the database, I want registerprocess.php to redirect back to ...

Is it possible to retrieve the complete file path in a form?

My goal is to retrieve a file using an input element of type "file". This element is located within a partial view, and I need to send it to the controller or request it there using "Request.Form["inputFile"];". However, this method only provides me with t ...

Tips for effectively implementing a curried selector function with the useSelector hook in react-redux

In my project using react-redux with hooks, I encountered a situation where I needed a selector that takes a parameter which is not passed as a prop. Upon checking the documentation, it mentioned: The selector function does not receive an ownProps argum ...

Click a button to spin images around

Is there a way to rotate an image by 90 degrees, 180 degrees, and 360 degrees with the click of a button? <img class="test" id="image" src="images/image" alt="This is the Display Image" /> I attempted to use the following script, but was not satisf ...

When using `getStaticPaths` in Next.JS, an error may be triggered if `fallback: true` is set and there are issues loading static props

For more information, please visit the discussion here. I encountered a similar issue. Everything was functioning properly when fallback was set to false. However, setting fallback to true resulted in Next.js throwing an error. throw new Error('Faile ...

Utilizing ECMA 5 code within Internet Explorer 8

My current code includes the use of hls.js for playing hls streams. The original code is in ECMA version 6 and then transpiled into ECMA 5, which can be found in the dist folder (link provided). It works fine in most cases. However, when trying to render ...

Modifying the nginx configuration file for an Angular application: a step-by-step guide

After deploying my Angular application on an nginx server, I encountered a problem. When I accessed http://**.8.100.248:30749, it displayed the default index.html page from the nginx server instead of my actual application located in the html folder under ...

Update the radio group model's value within the ngChange function

My form consists of 3 radio buttons with the same name="myNumber" and a function to handle the ng-change event. <form name="myForm" ng-controller="ExampleController"> <label> <input type="radio" ng-model="number" name="myNumber" value ...

Utilizing jQuery to extract the id and update its content

One of my tasks involves working with a table generated by PHP and incorporating a modal that allows users to change the text produced by the variable $l_id. I have a link with a class "eloc" that triggers the display of the modal div section. By intercept ...

Verifying API access with custom settings using the got module

I'm having some trouble with a basic API call that requires authentication using the got library. I tried using the options parameter to pass my username and password, but I keep getting an HTTPerror. Could someone please review my usage of the optio ...

Initiating a conversation using a greeting in the Javascript bot framework

I am looking to initiate a multi-level, multiple choice dialog from the welcome message in the Bot Framework SDK using JavaScript. I have a main dialog (finalAnswerDialog) that utilizes LUIS for predicting intents, and a multi-level, multiple choice menu d ...

What is the best way to include a new class into the current class in this particular scenario?

Just starting out with Javascript and Jquery, so please bear with me if this question seems basic I'm dynamically constructing HTML like this: var favoriteresultag = '<ul>'; favoriteresultag += "<section id='"+name+"' ...