Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

css :first-child selector will not work when using *ng-for #4805

Closed
rolandjitsu opened this issue Oct 18, 2015 · 12 comments
Closed

css :first-child selector will not work when using *ng-for #4805

rolandjitsu opened this issue Oct 18, 2015 · 12 comments
Labels
effort1: hours help wanted An issue that is suitable for a community contributor (based on its complexity/scope). type: bug/fix
Milestone

Comments

@rolandjitsu
Copy link

It seems like when using *ng-for="item of items" to render a list of items, if I want to use the :first-child selector it will not work as expected. It looks like right before the first item, there is a <script></script> tag inserted, so the rendering ends up as:

<ul>
    <script></script>
    <li></li>
    <li></li>
    <li></li>
</ul>

Probably that is intentional, but it should be taken into consideration that this would break the expected behaviour of :first-child and a fix for it might be a good idea.

@ericmartinezr
Copy link
Contributor

You're right, I ran into this a while ago. This happens with *ng-if, *ng-for and probably any other directive that uses *. I just workaround it by iterating over the children and finding the first element I needed. In your case you can use :first-of-type for now.

Edit
I know that's not the point. Anyway, this not only affects :first-child, it may affect others css selectors +.

<div></div>
<script></script>
<span *ng-if="..."></span>
// css..
div + span {} // won't work

@rolandjitsu
Copy link
Author

I know I can use :first-of-type, but that's not the point. On lists such as ul or ol that expect that all the children are li it should not insert anything else along with the li. It's also a little weird the first time you see that :first-child doesn't work and you have no clue why is that.

@EmmanuelDemey
Copy link
Contributor

According to the HTML5 spec, ul element can containt Zero or more li and script-supporting elements.

And for you (and for me :D) I check the definition of script-supporting elemens :

Script-supporting elements are those that do not represent anything themselves (i.e. they are not rendered), but are used to support scripts, e.g. to provide functionality for the user.

The following elements are script-supporting elements: script template

So we can have script as a first child a ul element.

But you are right, it is not very developer-friendly to have this kind of element. I do not like frameworks that insert tags in my HTML.

What is the content of this tag ?

@vicb
Copy link
Contributor

vicb commented Oct 19, 2015

What is the content of this tag ?

There is no content, it marks place where views can be inserted.

@rolandjitsu
Copy link
Author

@Gillespie59 as @vicb said, there is no content, it's just an anchor for angular 2 to know where to insert views. In my case it's the place where *ng-for knows to add more li elements (next to it).

@mhevery
Copy link
Contributor

mhevery commented Oct 22, 2015

@tbosch we should switch back to <!-- anchor --> with the new compiler, which would make this problem go away.

@mhevery mhevery added P2: required effort1: hours help wanted An issue that is suitable for a community contributor (based on its complexity/scope). type: bug/fix labels Oct 22, 2015
@scatcher
Copy link
Contributor

scatcher commented Nov 4, 2015

Just for clarification, we currently have the ability to set additional attributes on the script template anchor. Is there a situation where we need to be able to retain this functionality? If not, converting to a comment seems like the right answer.

@adamdbradley
Copy link
Contributor

Would this be able to make it into Beta00?

@IgorMinar
Copy link
Contributor

@tbosch can you take a look and determine if this should/can be in beta?

@tbosch
Copy link
Contributor

tbosch commented Nov 10, 2015

yes

tbosch added a commit to tbosch/angular that referenced this issue Nov 10, 2015
tbosch added a commit to tbosch/angular that referenced this issue Nov 11, 2015
@tbosch tbosch closed this as completed in bb9cfe6 Nov 14, 2015
jeffbcross added a commit to jeffbcross/angular that referenced this issue Nov 20, 2015
… template>` elements

Originally authored by @tbosch, this reverts the revert commit
e274ff8.

Closes angular#4805
@jeffbcross
Copy link
Contributor

Reopening since the commit was reverted, though hopefully PR #5416 will land soon.

@jeffbcross jeffbcross reopened this Nov 20, 2015
@tbosch tbosch added this to the beta.0 milestone Dec 4, 2015
vsavkin pushed a commit to vsavkin/angular that referenced this issue Dec 10, 2015
… template>` elements

Originally authored by @tbosch, this reverts the revert commit
e274ff8.

Closes angular#4805
@angular-automatic-lock-bot
Copy link

This issue has been automatically locked due to inactivity.
Please file a new issue if you are encountering a similar or related problem.

Read more about our automatic conversation locking policy.

This action has been performed automatically by a bot.

@angular-automatic-lock-bot angular-automatic-lock-bot bot locked and limited conversation to collaborators Sep 7, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
effort1: hours help wanted An issue that is suitable for a community contributor (based on its complexity/scope). type: bug/fix
Projects
None yet
Development

Successfully merging a pull request may close this issue.

10 participants