Rubén Jiménez
Rubén Jiménez

Reputation: 1845

AngularJS: Removing HTML element from DOM, but not its content

I'm using AngularJS and I've got a doubt.

I have something like this:

<a href="#">
 <p>Hello World!</p>
</a>

I want to remove the anchor, but not its content. If I use ng-show/ng-hide, according to the condition it removes everything, the anchor and even the paragraph.

How can i remove just the anchor keeping the content displayed (but unlinked)?

Thanks!

Upvotes: 0

Views: 961

Answers (2)

Satpal
Satpal

Reputation: 133403

Might not be best approach.

You can use

<a ng-if="condition == false">
 <p>Hello World!</p>
</a>    
<p ng-if="condition == true">Hello World!</p>

In place of ngIf you can use ngShow or ngHide

Upvotes: 1

Joao Leal
Joao Leal

Reputation: 5542

use ng-href and an expression:

<a ng-href="{{show()? '#' : ''}}">
 <p>Hello World!</p>
</a>

Upvotes: 2

Related Questions