好吧,好像watchGroup不支持深度监视。因此,您可以通过注册一个匿名的深度监视程序,并通过监视功能传递值数组来进行黑客入侵。
$scope.$watch(function(){ return ['number1','number2','myArray'].map(angular.bind($scope, $scope.$eval)); }, function(newV){ console.log(newV); },true);演示版
或仅将此函数添加为rootScope上的实用程序函数,并从任何继承的范围访问它。
.run(function($rootScope){ $rootScope.deepWatchGroup = function(exp, callback){ if(!angular.isArray(exp) || !thisScope.$watch) return; //Or log some error if array is not passed in or the context is not really a scope object var thisScope = this, //get scope evalFunc = angular.bind(thisScope, thisScope.$eval); //and a bound eval func thisScope.$watch(function(){ return exp.map(evalFunc); //return array of evaluated values }, callback,true); }});并从您的控制器执行以下操作:
$scope.deepWatchGroup(['number1','number2','myArray'],function(newV){ console.log(newV);});演示版



