javascript - 查看多个 $scope 属性

标签 javascript angularjs events angularjs-watch

有没有办法使用 $watch

订阅多个对象的事件

例如

$scope.$watch('item1, item2', function () { });

最佳答案

从 AngularJS 1.3 开始,有一个名为 $watchGroup 的新方法。用于观察一组表达式。

$scope.foo = 'foo';
$scope.bar = 'bar';

$scope.$watchGroup(['foo', 'bar'], function(newValues, oldValues, scope) {
  // newValues array contains the current values of the watch expressions
  // with the indexes matching those of the watchExpression array
  // i.e.
  // newValues[0] -> $scope.foo 
  // and 
  // newValues[1] -> $scope.bar 
});

关于javascript - 查看多个 $scope 属性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11952579/

相关文章:

javascript - Angular UI Grid 重新加载单元格模板

javascript - 在 AngularJS 中选择所有复选框

jQuery 更改然后模糊事件

javascript - 如何移动嵌套数组中的元素

javascript - 添加此 Twitter 关注按钮自定义

javascript - 如何清除 session cookie

javascript - 在 Javascript 中管理多种日期格式

Javascript/HTML onclick 将新值传递给正在运行的内容 slider

javascript - 使用 onkeydown 事件在一个函数中插入 click 事件

javascript - 使用 setState 更改复选框的状态