title: how to pass data from one function to another function angularjs
body: <p>I am filtering data while searching in my application. I am facing the issue to write if condition to check the function selected data and second function filter data.</p>
  
  <ul>
  <li><p>I have 5 side menus in my application. If I click any one of that, I need to store that value in a variable.</p></li>
  <li><p>I have another function, I am looping the results there.But I need to check already stored value, and the current function's response value is same or not.</p></li>
  </ul>
  
  <pre class="lang-js prettyprint-override"><code>$scope.toggleTab = function (id) {
        $scope.categoryId = id;
  }
  </code></pre>
  
  
  
  <p>And my another function is,</p>
  
  <pre class="lang-js prettyprint-override"><code>$scope.getTags = function () {
      var keywords_regex = new RegExp($scope.search.split(' ').map(function (i) { return '(?=.*' + i + ')'; }).join(''), 'i');
        return $scope.getData.filter(function (data) {
          return !!data.match(keywords_regex);
        }).map(function (data) {
            return data;    
        });
      }
  </code></pre>
  
  
  
  <p>In this map function I need to check the result like this,</p>
  
  <pre class="lang-js prettyprint-override"><code>      }).map(function (data) {
           if( selectedData == data.id){
           return data;
           }
  
        });
  </code></pre>
  
  
  
  <p>How can I do this, I used $rootScope. But When it came inside loop, the result has changed..</p>