Removing element from DOM via ng-if bound to attribute directive scope property
<p>I assumed this would be straightforward, but it's seemingly not!</p>

<p><strong>I'm trying to create a generic attribute directive that will call a method in one of my services and conditionally cause the element in which it is placed to not be added to the DOM if the service method returns false. Basically, ng-if, but an ng-if that internally calls a service method and acts on that</strong></p>

<p><a href="https://plnkr.co/edit/mixfuE?p=preview" rel="nofollow">Link to Plunker</a></p>

<p>I have an element containing an attribute directive: e.g</p>

<p><code>&lt;p ng-if="visible" my-directive&gt;Hi&lt;/p&gt;</code></p>

<p>I set <code>visible</code> to true in the myDirective directive. I was <em>expecting</em> the <code>&lt;p&gt;</code> element to be removed from the DOM when <code>visible</code> was falsy and added to the DOM when it's truthy. Instead, the ng-if never seems to spot that visible has been set to true in the directive's link function and, hence, the <code>&lt;p&gt;</code> element never displays.</p>

<p>I wasn't 100% sure it would work since the directive is removing the element on which it exists, bit of a catch 22 there. </p>

<p>I've spent far too long on this and have so far tried (unsucessfully):</p>

<ul>
<li>Adding an ng-if attribute in the link function via these two methods

<ul>
<li><code>attr.ngIf = true;</code></li>
<li><code>element.attr('ng-if', true);</code></li>
</ul></li>
<li>Changing the ng-if in the <code>&lt;p&gt;</code> to ng-show, thereby not removing the element (which I really want to do)</li>
</ul>

<p>I'm wondering if it's something as simple as scope? Since the ng-if is bound to a property of the <code>&lt;p&gt;</code> element, is setting <code>visible</code> in the directive scope setting it on the same scope?</p>

<p>On the other hand, I may be drastically over-simplifying, I have a nasty feeling I may have to consider directive compilation and transclusion to get a solution for this.</p>

<p>Does anyone have any feel for where I might be going wrong?</p>