AngularJS watch an object property in an object array

后端 未结 4 1636
日久生厌
日久生厌 2021-02-06 20:56

I have this data in my controller

    $scope.data = {
        home: {
            baseValue: \"1\",
            name: \"home\"
        },
        co         


        
4条回答
  •  忘掉有多难
    2021-02-06 21:11

    You can watch an object attribute.
    So you can do something like

    for(var key in $scope.data) {
      if($scope.data.hasOwnProperty(key)) {
        $scope.$watch("data['" + key + "'].baseValue", function(val, oldVal) {
          // Do stuff
        });
      }
    }
    

    Not tested, but the idea is simple.

提交回复
热议问题