title: directive with ng-if not rendering in Angular.js
body: <p>I'm trying to render a directive whenever I get the search results back. My plan was to keep a scope variable <code>algoliaSearch</code> initially <code>false</code> and whenever I get back search results I change it to <code>true</code>. Then in my view I tried to render the directive based on the value of my variable.</p>
  <pre class="lang-js prettyprint-override"><code>  .directive('searchResults', function () {
      return {
        restrict: 'E',
        templateUrl: 'app/search/directives/templates/searchResults.template.html',
        controller: ['$scope', 'AlgoliaSearchService', function ($scope, AlgoliaSearchService) {
          $scope.hits = [];
          $scope.nbHits = null;
          $scope.algoliaSearch = false;
  
          AlgoliaSearchService.on('result', results =&gt; {
            $scope.algoliaSearch = true;
            $scope.hits = results.hits;
            $scope.nbHits = results.nbHits;
            console.log($scope.algoliaSearch)
          });
  
        }]
      };
    })
  </code></pre>
  <p>In my view I want to render the directive when I get the search results back</p>
  <pre class="lang-html prettyprint-override"><code>&lt;search-results ng-if=&quot;algoliaSearch&quot;&gt;&lt;/search-results&gt;
  </code></pre>
  <p>But it doesn't seem to work. It doesn't render anything on searching and even <code>console.log($scope.algoliaSearch)</code> doesn't print anything on console.
  However if i use like</p>
  <pre class="lang-html prettyprint-override"><code>&lt;search-results&gt;&lt;/search-results&gt;
  </code></pre>
  <p>or</p>
  <pre class="lang-html prettyprint-override"><code>&lt;search-results ng-if=&quot;true&quot;&gt;&lt;/search-results&gt;
  </code></pre>
  <p>Then it renders and the <code>console.log</code> works but that is not the way I want to.<br />
  My problem is why it doesn't conditionally render the directive based on my scope variable.
  I want to make it render conditionally once I get back the search results.<br />
  Any help is much appreciated.</p>