How to use $ watch to view changes when updating a database record

I have nightmares on how to display in the user interface what I changed in my database. I have such a scenario that I need to select certain headers, and then I press a button that will change its status.

The problem is when I select the headers, and then I press the status change button, which does not automatically reflect on the user interface. Here is my update function.

$scope.updateTitleStatus = function(statusId, cp){
        ContentAssessmentService.updateSelectedTitles($scope.selectedTitles, statusId);
        $scope.selAll = !$scope.selAll;
        $scope.selectedTitles = [];
    };

Here is my favor.

this.updateSelectedTitles = function(selectedTitle, statusId){
    var self = this;
    _.forEach(selectedTitle, function(selectedTitle){
        ContentAssessmentFactory.updateSelectedTitleStatus(selectedTitle.id, statusId);
    });
};

Here is my array, which is the selected header.

$scope.selectedTitles = [];

Can you tell me how to use the $ watch function? I do not know how to do that. I did it, but it does not work.

$scope.$watch(function($scope){
        return $scope.selectedTitles;
    }, function(newValue) {
        $scope.selectedTitles = newValue;
        console.log(newValue);
    });

, ( , ), .

+4
1

. $watch "" . @scope, . , , meteor.js, websocket , , .. . angular, api angular, api .

+3

All Articles