How to $watch multiple variables?

后端 未结 4 1104
天命终不由人
天命终不由人 2021-02-02 17:36

I do have two $scope variables. They are called $scope.image and $scope.titleimage.

Basically the store the same type of contents.

4条回答
  •  既然无缘
    2021-02-02 18:29

    The correct answer was found here:

    https://docs.angularjs.org/api/ng/type/$rootScope.Scope#$watchCollection

    "for arrays, this implies watching the array items; for object maps, this implies watching the properties"

    Example:

    $scope.$watchCollection(function () {
        return {t : ctrl.time, d : ctrl.date};
    }, function(value) {
        ctrl.updateDateTime();
    });
    

提交回复
热议问题