The functionality of $watch is not functioning correctly within the Modal, despite implementing it with $scope.user={pwd1:''}

For the Plunker link referenced, please click here: http://plnkr.co/edit/0vOjw0?p=preview

index.html


        <!DOCTYPE html>
        <html ng-app="app">

        <head>
        <link rel="stylesheet" href="style.css">

        <script src="angular.min.js?version=1.4.2"></script>
        <script src="ui-bootstrap.js"></script>
        <script src="script.js"></script>
        </head>

        <body>

        <div class="col-lg-2" style="margin-right: 7px;float: left;">
            <button ng-controller="registrationCtrl" type="button" class="btn btn-primary btn-responsive" ng-click="openRegistration()"> Registration</button>
        </div>

        </body>

        </html>
    

registration.html


        <div class="modal-dialog" id="registration.html">

        <div class="modal-body">

            <form name="form" class="css-form" novalidate>

            <label for="pw1">Password:</label>
            <input type="password" id="pw1" name="pw1" ng-model="user.pw1" ng-required="" />
            <div>{{user.pw1}}</div>

            </form>

        <div class="modal-footer">

            <button class="btn btn-warning" ng-click="cancel()">Cancel</button>
        </div>
        </div>
        </div>
    

script.js


        angular.module('app',['ui.bootstrap']).controller('registrationCtrl', ['$scope','$modal',function ($scope, $modal) {

            $scope.openRegistration = function () {
                var modalInstance =$modal.open({
                    templateUrl: 'registration.html',
                    controller: 'registrationPopupController',
                    backdrop: 'static',
                    keyboard: false,
                    size: 'sm'
                });
            }
        }]).controller('registrationPopupController', ['$location','$scope','$modalInstance',function ($location,$scope,$modalInstance,LoginService) {

            $scope.user={
                pwd1:''
            };
            $scope.$watch('user.pwd1',function(newV,oldV){
                if(newV!=oldV){
                    alert(newV)
                    console.log(newV,oldV);
                }
            },true);


            $scope.cancel = function () {
                $modalInstance.dismiss('cancel');
                location.href='#/';
            };
        }]);
    

The issue I'm encountering is that when I type in the password text box, my $watch function does not trigger in the modal instance controller. However, it works when I type in the same simple controller. Can someone please provide assistance with this?

Answer №1

You made a mistake in your ng-model value, it should be changed to user.pwd1 instead of user.pw1

Code Example

<input type="password" id="pwd1" name="pw1" ng-model="user.pw1" ng-required="" />

Working Plunkr

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

DOM doesn't reflect changes to nested object when component prop is updated

I have a complex object structured in a multidimensional way that appears as follows: obj: { 1: { 'a' => [ [] ], 'b' => [ [] ] }, 2: { 'x' => [ [], [] ] } } This object is located in the r ...

Sending data from JavaScript to PHP using the POST method

I recently learned that using ajax for data passing doesn't require a form or hidden value. I'm hoping to find an example to better understand how it works. index.js: function collectData(r) { // identifies the row index var i = r.pare ...

Utilizing ng-class to dynamically change glyphicons for sorting a table

I've been encountering some difficulties with implementing the ng-class feature. I have a table that can be sorted in ascending and descending order by clicking on the glyphicon-chevron-down. However, I'm struggling to get it to work properly. M ...

Prevent access to Express routes until the route has completed its execution

I am currently working on an Express REST-API route that involves various database actions. My goal is to prevent any other calls from being made to the REST-API until the actions within this particular route have been completed. When this route is access ...

Calling Ajax inside each iteration loop

I have encountered numerous posts discussing this topic, but the solutions I came across do not quite suit my needs. Some experts suggest changing the code structure, however, I am unsure of how to go about doing that. What I desire: 1) Retrieve a list ...

Timeout error occurs in Jasmine spec during execution of Protractor tests on a selenium server located remotely

My Protractor tests work perfectly when run locally with directConnect set to true. However, when I attempt to execute them on a remote Selenium server (Grid), I consistently encounter the following error message: The WebDriver Control Flow has been reset ...

Placing elements from an array into a customized output

Currently, I am dealing with a unique output: dAmn_Raw('send chat:Sandbox\n\nmsg main\n\nthismessage'); In my code, there exists a variable: myvariable that stores a random value selected from an array I formulated. The cha ...

Executing scripts within various node project directories using npm

Creating Concurrent NPM Scripts In my main project, I have several node projects nested as subdirectories. Each of these projects has its own node_modules directories and package.json files. My goal is to define an npm script in the main project's pa ...

Guide on implementing two submission options in an HTML form using JavaScript

Currently, I am working on a form that includes two buttons for saving inputted data to different locations. However, I am facing an issue with the functionality of the form when it comes to submitting the data. Since only one submit function can be activa ...

Discover the joy of reading with wrap/unwrap to consume more content in less

I am experimenting with a 'read-more read-less' feature using a wrap method that currently only works for the 'show more' functionality. So, to clarify, if the text exceeds a certain length, I truncate it and insert a read-more-link ( ...

Making HTTP requests with axios in Node.js based on multiple conditions

I'm facing an issue with making get calls using axios to both activeURl and inactiveURl. The goal is to handle error messages from the activeUrl call by checking data from the inactiveUrl. However, I keep receiving error messages for the inactiveURL e ...

Opening a Bootstrap Modal in React without relying on npm react-bootstrap

I've been trying to create a Modal in React.js using Bootstrap5, but I'm unable to use npm react-bootstrap for various reasons. I attempted an approach where I utilized state to set Modal classes with a button, which worked well with my NavBar, b ...

Combine iron-page and bind them together

Recently, I've started learning about Polymer and I want to bind together paper-tabs and iron-pages so that when a tab is clicked, the content loads dynamically. After going through the documentation, this is what I have tried: <app-toolbar> ...

Unable to perform 'put' operation on 'idbObjectStore' due to empty result when evaluating the object store's key path

An error has occurred in a chrome-based APP that I am currently supporting. Despite my attempts to investigate further, I have been unable to determine the cause of the error. Can someone please explain to me the potential reasons behind this issue? The e ...

NodeJS produces identical outcomes for distinct requests

RESOLVED THANKS TO @Patrick Evans I am currently working on a personal web project and could use some assistance. In my website, users are prompted to upload a photo of their face. When the user clicks the "upload" button, the photo is sent with a request ...

Obtaining the Div ID After Clicking on a Link

I'm attempting to fade out a box once the X in that box is clicked. I haven't been able to make it work even after searching on Google. I managed to get it working when clicking the div itself using $(this), but my goal is for it to work when the ...

Issues encountered when trying to use the export default syntax in Vue components

Programming Issue I attempted to execute the provided code, but unfortunately, it does not work and no output is visible in the browser. Is there an alternative method for writing code within <scripts setup> </script>? I have understood that f ...

Adding various react elements to a list with the click of a button: A step-by-step guide

I am faced with a challenge where I have two different types of components that I want to display on the screen when a button is clicked. However, I don't want to simply show and hide the components. Instead, I want to be able to dynamically generate ...

Organizing pictures by category

I am currently working on creating an interactive image gallery with sorting options based on different categories such as land, sea, animals, and more. I have created a small example to demonstrate my concept. My objective: is to allow users to select a ...

Checking authorization with CognitoUser solely for "code" provided by CognitoUser (npm: amazon-cognito-identity-js)

Currently, I am in the process of implementing the "forget password" feature. However, I have encountered an issue where I would like to verify the "verification code" first before setting a new "password". Unfortunately, the system currently requires bo ...