1

Im trying to create a basic directive that puts an image on the page. The image is contained in a

tag that may or may not be shown depending on a ng-show value. so, something like

<p ng-show="showImage">
  <imageDir></imageDir>
</p>

The directive works fine, but it never actually stays within the

tag, and it will be shown all the time, regardless of the value of showImage

Can anyone tell me why?

Here's a plunkr that shows the issue http://plnkr.co/edit/gPXezknXe2mBYztm9QO2?p=preview

1
  • 1
    "The P element represents a paragraph. It cannot contain block-level elements (including P itself)." reference Commented Dec 6, 2013 at 19:58

2 Answers 2

1

Just change <p> to <div> and it works fine: plnkr.


<p> only accepts so called phrasing content and your directive -- for obvious reasons -- does not belong to this group. So browser just put it outside of the <p>.

Sign up to request clarification or add additional context in comments.

Comments

1

The reason is: putting a div in a p causes invalid markup. Use inline tag instead , like span for example:

<p ng-show="false">
    <span gravatar email-hash="09s7dvywoifhowvw5"></span>
</p>

Working: http://plnkr.co/edit/VSKq02?p=preview

2 Comments

Thanks guys both these answers worked .. Wish I could select two answers though
@Cheyne it is ok , i'm not chasing for reputation :)

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.