-1

I have this code

$scope.setContent = function (data) {
        if ($scope.unfiltered_tree == null) {
            $scope.unfiltered_tree = data;
        }
   }

the data saved in the unfiltered_tree for the first time,and when new data comes it's not saved.

Any help on that?

Bogdan
  • 43,166
  • 12
  • 128
  • 129
Mohammad AL-Raoosh
  • 721
  • 1
  • 12
  • 32

1 Answers1

0

I do not fully understand your question. Are you asking how to ALWAYS store the new data in your variable? Just remove the if statement.

$scope.setContent = function (data) {
        $scope.unfiltered_tree = data;
   }

The purpose of the if statement may have been to check if your variable has been intialized or not. In that case you may want to use the following format:

$scope.setContent = function (data) {
        if (!$scope.unfiltered_tree) {
            // Variable has not been initialized yet
            $scope.unfiltered_tree = data;
        } else {
            // Variable has been initialized before, do something else
          }
   }
ctotolin
  • 183
  • 5