AngularJS : Why ng-model value not updating in scope variable

喜夏-厌秋 提交于 2019-12-04 04:30:06

Problem

You cant use $scope.$watch for this condition, because the $scope.$watch is calling for whenever the $scope.startTime value is changed, If you select $scope.startTime value is a previous value, then this below code is not called.This is why you got this problem

if( ($scope.startTime !== undefined) &&  ($scope.startTime !== null) && ($scope.startTime !== '') )
                {
                    $scope.endTime =  new Date($scope.startTime.getTime() + (15*60*1000));

                    console.log($scope.startTime);
                    console.log($scope.endTime);
                }   

Review

This issue only happen with your previous value.Once you change any other value then it's working good.

Solution

You need change to ng-blur instead of $scope.$watch in your first text field.

Fixed Demo

I have solved your issue by using ng-blur. Please see this Plunker

also my demo have working your reset functionality :) good luck

I resolved this problem using this code for reset

angular.element('#elementId').timepicker('setTime', null);

With this code, model value also updates with previous value.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!