title: How do I conditionally add a filter to ng-repeat inside directive?
body: <p>I am using an element directive on several views. The directive repeats for each 'resource' in a list of resources, simply like this: <code>ng-repeat="resource in resources"</code>.</p>
  
  <p>Different page controllers will determine which resources will get pulled from the API by having a different <code>$scope.resourceApiPath</code> in each view controller that the directive controller then uses to make an <code>$http</code> call.</p>
  
  <p>This works well for different views that display different resources. For example one view displays all the user's own resources, one view displays public resources, one view displays resources the user has starred, etc. </p>
  
  <p>The only problem is that for one of my views I want to add a filter on the <code>ng-repeat</code> like so: <code>ng-repeat="resource in resources | filter:resourceSearch.text"</code>. is there a way for me to add this filter depending on a condition, e.g. if <code>$scope.filter == true;</code>, otherwise simply returning the regular <code>ng-repeat="resource in resources"</code>?</p>
  
  <p>This is my directive:</p>
  
  <pre><code>.directive('resourcePanel', function() {
      return {
          restrict: 'E',
          scope: false,
          templateUrl: 'scripts/templates/resource-panel.html',
          controller: 'ResourcesPanelController'
      }
  })
  </code></pre>
  
  <p>The <code>ResourcesPanelController</code> referenced in the directive has something like this:</p>
  
  <pre><code>$scope.resources = [];
  $scope.loadResources = function() {
      $scope.resources = []; // Empty the array
      $http.get('/api/resource' + $scope.resourceApiPath)
          .then(function(res) {
              $scope.resources = res.data.message;
          });
  };
  $scope.loadResources();
  </code></pre>
  
  <p>The <code>scripts/templates/resource-panel.html</code> element template looks something like this:</p>
  
  <pre><code>&lt;div class="panel" ng-repeat="resource in resources"&gt;
      {{resource.content}}
  &lt;/div&gt;
  </code></pre>
  
  <p>Thanks!</p>