0

My web page looks like (abbreviated)

<HTML ng-app="scanning">
...
<BODY ng-controller="scanningController">
<INPUT id=R_name maxLength=50 size=35 ng-bind='BOOKING.R_NAME'>
</BODY>
</HTML>

My code is

function scanningController($scope){
    $scope.depot = depot;
    $scope.BOOKING = {R_NAME: ''};
    /* Does anything get changed. */
    $scope.$watch('BOOKING', function() { 
        ...
    }, true);
}

var scanningModule = angular.module('scanning', []);
scanningModule.controller('scanningController', scanningController);

The watch event does not get called when the user changes the value of R_NAME via the textbox. It does get called when the page initially loads, just not when values are changed by the user. I have forced the event to fire by using an interval timer, changing a test property and calling $digest. In that case when I debug I can see that nothing entered through the textbox has been stored on the object. So it seems that I have not setup databinding correctly.

1
  • if u watch for BOOKING.R_NAME everything should be fine Commented Jun 24, 2014 at 13:20

1 Answer 1

1

You should use ng-model for two-way binding instead of ng-bind.

<INPUT id="R_name" maxLength="50" size="35" ng-model="BOOKING.R_NAME">

You can also use ng-change instead of adding a $watch in your controller

<INPUT id="R_name" maxLength="50" size="35" ng-model="BOOKING.R_NAME" ng-change="onChange()">

Controller

function scanningController($scope){
    $scope.depot = depot;
    $scope.BOOKING = {R_NAME: ''};
    /* Does anything get changed. */
    $scope.onChange = function () { 
        ...
    };
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.