Answer the question
In order to leave comments, you need to log in
Why doesn't watch work in angular.js?
there is this piece of code:
$scope.edit_node = function (scope) { // когда приступаю к редактированию подчиненного узла
$scope.singleData = scope.$modelValue; // добавляю редактируемый узел
$scope.singleData.parent_scope = scope.$parentNodeScope; // добавляю его родителя
};
// при любом изменении родителя хочу знать об этом
$scope.$watch('singleData.parent_scope', function (val) {
console.log('parent_scope updated!');
});
Answer the question
In order to leave comments, you need to log in
Try adding a 3rd parameter with value true to the $watch call.
UPD
Maybe just send notifications when there is a change? In the edit_node function, make $scope.$emit / $scope.$broadcast (depending on where in the hierarchy you need to send them).
Of course I tried!
There the nesting is large (a bunch of objects that refer to other objects) an error pops up.
in the end, he began to follow not the whole singleData.parent_scope , but singleData.parent_scope.$childNodesScope.$modelValue.length' . seems to work)
if you change the data in the code - just notify in the place of the change that you have changed something. If you change through the UI - there is ng-changed. deep watch is a mega-castle that reduces control and increases the likelihood of problems in the future.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question