ng-bind value not updating second time when updating from controller

862 views Asked by At

i am trying to bind value in label when i get signal in session. for first it shows values in label but when i send signal second time it shows blank label and is not updating value.

code i am using

HTML

<div class="modal-content">
            <h4>Incoming Call From...</h4>
            <label class="alignCenter incomingReason">{{requestedCall.reason}}</label>
            <label class="alignCenter">{{requestedCall.hname}}</label>
</div>

Controller

session.on("signal:chat", function (event) {            
                    var data = JSON.parse(event.data);
                    $scope.requestedCall.reason = data.complain_name;
                    $scope.requestedCall.hname = data.username;
                    $scope.PlayRingtone();
                    $scope.$apply();
                    $scope.showModel();                                                         
    });

when i send signal , i gets data in var data = JSON.parse(event.data);

i always have to use $scope.$apply() other wise it doesn't bind value for first time also but for second time it doesn't work at all.

i have tried $timeout , $digest but nothing works at all , any help would be appreciated.

1

There are 1 answers

1
Hamza Baig On

When we are out of angular, things doesn't work. So if you are doing something in jQuery or any other library angular will not know what has been changed. For that you've to tell angular explicitly by using $apply or $digest

$scope.$apply(function () {
    $scope.requestedCall.reason = data.complain_name;
    $scope.requestedCall.hname = data.username;
    $scope.PlayRingtone();
    $scope.showModel();   
});

Let me know if it works!