0

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!

3
  • I would suggest that you use a directive for this kind of thing. Commented Sep 12, 2014 at 11:40
  • why can't you remove it from template? or use ng-if or ng-switch You haven't provided any conditions Commented Sep 12, 2014 at 11:47
  • When you want it to happen? On page load, or you want to be able to return element back on some condition? Commented Sep 12, 2014 at 11:53

2 Answers 2

2

use ng-href and an expression:

<a ng-href="{{show()? '#' : ''}}">
 <p>Hello World!</p>
</a>
Sign up to request clarification or add additional context in comments.

3 Comments

But the content (<p></p>) will remain linked, won't it? What i want is removing the anchor totally.
his answer will work... i was going to answer his, here's a plnkr related to this answer... plnkr.co/edit/bGn2csAF3JtZpEql9O9s?p=preview
The tag will remain there, but since the href attribute will be empty, there won't be any link. If you want to completely remove the anchor tag, then I recommend using a custom directive.
1

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

1 Comment

Yep, it occurred to me, but i also thought it may not be the best approach... Anyway, if there is not any best answer, that one will be what i'll use.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.