Skip to content
This repository was archived by the owner on Apr 12, 2024. It is now read-only.

ngif strange behavior on directive template #11855

Closed
Mushr0000m opened this issue May 12, 2015 · 2 comments
Closed

ngif strange behavior on directive template #11855

Mushr0000m opened this issue May 12, 2015 · 2 comments

Comments

@Mushr0000m
Copy link

Hi,
I'm not sure it's an issue, but I think. Let me explain, when using ng-if in the template of a directive, and then in the link method trying to select the element the object return is empty, even if the element exists by passing the ng-if validation. Of course no problem if using ng-show.

An example here : http://plnkr.co/edit/8vBzoL640k3j7U3GW04T?p=preview
Try to modify the plunker by changing ng-if to ng-show and the element is logged in the console.

I hope it's just me missing something.

Thanks !

@gkalpak
Copy link
Member

gkalpak commented May 12, 2015

This is how ngIf works (i.e. how all directives with transclude: '$element' work).
At the time you are trying to find your template element, there is only a placeholder comment-node in the DOM. The actual template is inserted at a later time.

E.g. if you wrap the code inside of a $timeout() you will be able to inspect the element normally.

That said, this is a general support question and as such should have been directed to the appropriate channels.
GitHub is reserved for bug reports and feature requests.

@Mushr0000m
Copy link
Author

Thanks for your answer and sorry for the mistake, I thought it was maybe a bug related to other already on GitHub with Directives and ngId + TemplateUrl like : #7183 or #9837.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

2 participants