issue with data binding in ons-dialog

Utilizing an ons-dialog to display a popup prompting the user to sign up for a newsletter. I have set a 3-second timeout to prevent users from immediately closing the prompt without reading it or waiting.

I aim to initially show the dialog with the 'close' button disabled, then programmatically enable the button.

The following is my JavaScript code :

setTimeout(function() {
    try {                              
        $scope.myBool = "FASLE";
        document.getElementById('cancelButton').setAttribute('disabled', '');
    } catch(e) { 
        alert(e);
    }
}, 3000);

Below is my button code :

<ons-toolbar-button var="cancelButton" ng-disabled="{{myBool}}" id="cancelButton" ng-click="naviDialog.hide()">X</ons-icon></ons-toolbar-button>

I also inserted {{myBool}} in a text field of a dummy button to observe if it changes.... unfortunately, it does not update the screen until I click the dummy button. Even after seeing the change in the variable, the ons-button in the toolbar within my ons-dialog remains disabled.

It appears there might be an issue with binding? However, I'm uncertain....

Has anyone encountered this problem before?

EDIT:

Here is my HTML code:

    <ons-navigator var="myNav">
        <ons-page>
        <ons-toolbar inline>
            <div class="center">
                Join Us
            </div>
            <div class="right">
                <ons-toolbar-button ng-disabled="myBool" var="cancelButton" id="cancelButton" ng-click="naviDialog.hide()">X</ons-icon></ons-toolbar-button>
            </div>
        </ons-toolbar>

        <div style="text-align: center">

            <p>
            <i class="fa fa-envelope-o fa-4x"></i>
            </p>
            <p>
            Join our mailing list to receive special offers and insider information.
            </p>
            <input type="email" class="text-input text-input--underbar"
                placeholder="Email" value="" style="color:black; width:80%;">
                <p>
                <ons-button onclick="myNav.pushPage('signup.html')">Submit</ons-button>
                </p>
                </div>
        </ons-page>
    </ons-navigator>

Here is my controller code:

app.controller('welcomePopupController', function($http, $scope, $compile, $sce, $window, filterFilter){
            $scope.myBool = true;
                    setTimeout(function(){                        
                               try{
                               console.log('re-enabling button');
                               $scope.myBool = false;
                               }
                               catch(e){alert(e);}
                               }, 3000);
            });

Answer â„–1

Avoid using interpolation within the ng-disabled directive.

The correct syntax should be:

ng-disabled="myBool"

Update:

Another issue arose from utilizing setTimeout. When setTimeout is used, it operates outside of the Angular environment, therefore failing to trigger a digest cycle that updates watchers with property changes.

To resolve this, consider using $timeout, which will prompt a new digest cycle to occur.

In addition, implementing $timeout enhances the testability of the application.

Check out this article for more insights on $timeout.

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

Changing the CSS class of the Bootstrap datetime picker when selecting the year

Is there a way to change the CSS style of the Bootstrap datetime picker control so that when selecting years, the color changes from blue to red? I attempted to do this with the following code: .selectYear { background-color:red!important; } However ...

How can I use PHP to transform a JSON object containing xy coordinates into an image?

What is the best way to convert a JSON object containing xy coordinates into an image (PNG or JPG) using PHP or JavaScript? ...

Achieve automated zooming out using highcharts-ng through code

Currently, I am using Highcharts-ng as seen on https://github.com/pablojim/highcharts-ng Upon inspecting the source code, I have noticed some interesting functionalities in the directive utilizing scope.$on which I can leverage for broadcasting. One examp ...

Challenges with the Express server console

I have configured an Express Server and everything appears to be functioning correctly. The content I send is rendered in the browser, and my console.log test statements are being displayed in the terminal. However, when I inspect the browser page, nothi ...

Manipulating the content of a specific row's table cells with a text box in jQuery Datatables

I am working with a jQuery datatable that consists of only one column. Every time a row is selected, a panel opens with a text box that automatically populates with the name of the selected td. I am trying to figure out how to edit the name of the selected ...

Determining the Number of Sub-Menu Items Using jQuery without Reliance on CSS Classes

I've scoured the depths of Google and SO in search of answers, but nothing quite fits the bill. My mission is to create a submenu without using classes, adding a style attribute to each individual <li> within the sub <ul> that sets a min- ...

Stop the event propagation when the back button is clicked

While utilizing ons-navigator, I am looking to customize the function of a particular element at a certain stage. Employing the onClick handler has allowed me to successfully trigger this function. However, upon exiting the onClick handler, the navigator ...

Verifying Value Equality in all Documents with MongoDB

One feature on my website allows users to input a number into the field labeled subNum in a form. Upon submission of the form, I need to validate whether the entered value already exists within any existing document. This validation process is implemented ...

The slideshow feature on W3 Schools does not start automatically when the page loads

After following the W3Schools tutorial to create a slideshow, I found that the animations are working correctly. However, only three dots appear on the screen and I have to manually click on one of them to view the pictures. var slideIndex = 0; sh ...

Issues with Access-Control-Allow-Origin in .NET Core Deployment on IIS Set up on Windows Server 2016

I have checked various sources like Microsoft Documentation, SO Answers, and even installed IIS CORS module, but I am still struggling to get it right. The issue arises with my .NET Core API 3.1 hosted on IIS at AWS EC2 Windows Server 2016 datacenter, acc ...

Sinon.js: How to create a mock for an object initialized with the new keyword

Here is the code that I am working with: var async = require('async'), util = require('util'); var Parse = require('parse/node'); function signup(userInfo, callback) { var username = userInfo.username, email ...

Learn how to send information to a form and receive a response when a key is pressed, either up or down, by

Can you help with fetching data and passing it into a form to respond to customer names on keyup or keydown using JSON and PHP? <?php $conn = new mysqli("localhost", 'root', "", "laravel"); $query = mysqli_query($conn,"select * from customers ...

The Node.js server is failing to retrieve information from the AngularJS application

Having trouble reading data sent from an AngularJS client to the server via $http.post. Can't seem to figure out where I've made a mistake. var data = $.param({ id:$scope.user_id, }); alert(JSON.stringify(data)); $http.post('/getd ...

Looping through multiple AJAX calls

I have come across numerous questions on this topic, but I am still struggling to find a solution that will make my code function correctly. There is a specific function for calling AJAX that I am unable to modify due to security restrictions. Here is how ...

Utilize moment.js to format a datetime and display the corresponding timezone

I'm having trouble displaying timezones correctly using moment.js. I attempted to use the following code: var result = moment(someDate).format("MM/DD/YYYY HH:mm A Z"); This returns something like: 08/05/2015 06:18 PM +02:00, which is okay, but I w ...

Add slides in PowerPoint before or after the currently selected slide to enhance your presentation flow

I'm currently working on a function that pulls data from an API to convert PowerPoint presentations into base64 strings. Once I receive the response object, my goal is to seamlessly insert the slides into the existing presentation, exactly after the s ...

Ways to showcase a JavaScript popup on an Android WebView

Can a JavaScript popup window be opened on an Android web viewer that is coded similarly to this example from Google? If so, how can this be accomplished without closing the original background page and ensuring it resembles a popup as shown in the picture ...

Sending target information as a property argument

I have encountered an issue with my app's two Bootstrap modals. It seems that many people are facing problems with opening the second modal. Is it possible to pass data-target and modal id properties as props in this manner: data-target={props.da ...

When you click on a list item, the page transitions to the details page. However, the details page will only display the

At the moment, the main list HTML is functioning correctly <div class="post row" ng-repeat="(postId, post) in posts"> <a href="{{ post.url }}">{{ post.title }}</a> However, when I select an item from the list and navigate to a new p ...

"An ExceptionInInitializer error occurred - Can you provide more details,

An Issue Has Arisen: Exception in thread "main" java.lang.ExceptionInInitializerError at com.PoseidonTechnologies.caveworld.level.WoRe.<init>(WoRe.java:46) at com.PoseidonTechnologies.caveworld.CaveWorld.start(CaveWorld.java:80) at com.P ...