加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > 安全 > 正文

使用AngularJS可以将多个场景观看在一个表中吗?

发布时间:2020-12-17 08:14:33 所属栏目:安全 来源:网络整理
导读:参见英文答案 Watch multiple $scope attributes10个答案在AngularJS中有没有办法把这个结合到一个$手表中,或者我仍然需要每个手表的$手表? $scope.$watch('option.selectedContentType',function () { $scope.getData(); }); $scope.$watch('option.selec
参见英文答案 > Watch multiple $scope attributes10个答案在AngularJS中有没有办法把这个结合到一个$手表中,或者我仍然需要每个手表的$手表?
$scope.$watch('option.selectedContentType',function () {
        $scope.getData();
    });

    $scope.$watch('option.selectedContentStatus',function () {
        $scope.getData();
    });
您可以在下面找到有关如何使用$ watchCollection的一些变体

http://jsbin.com/IYofiPi/4 – working example here。

检查您的console.log以查看正在触发的事件。

观看数组的项目

$scope.cities = ['Salvador','London','Zurich','Rio de Janeiro']; //Array

$scope.$watchCollection('cities',function(newValues,oldValues) {
  console.log('*** Watched has been fired. ***');
  console.log('New Names :',newValues);
});

观察对象的属性

$scope.city = {
  name: 'London',country: 'England',population: 8.174
}

$scope.$watchCollection('city',newValues);
});

查看范围变量列表($ scope.firstPlanet,$ scope.secondPlanet)

$scope.firstPlanet = 'Earth';
$scope.secondPlanet = 'Mars';

$scope.$watchCollection('[firstPlanet,secondPlanet]',function(newValues){
  console.log('*** Watched has been fired. ***');
  console.log('New Planets :',newValues[0],newValues[1]);
});

Starting from AngularJS 1.3 there’s a new method called 07002 for observing a set of expressions.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读