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

Can we add "first-child" and "last-child" classes to ngFor? #10856

Closed
dopatraman opened this issue Aug 16, 2016 · 3 comments
Closed

Can we add "first-child" and "last-child" classes to ngFor? #10856

dopatraman opened this issue Aug 16, 2016 · 3 comments

Comments

@dopatraman
Copy link

I'm submitting a ... (check one with "x")

[ ] bug report => search github for a similar issue or PR before submitting
[ x ] feature request
[ ] support request => Please do not submit support request here, instead see https://github.com/angular/angular/blob/master/CONTRIBUTING.md#question

Current behavior
Right now ngFor renders a list of data as DOM elements.

Expected/desired behavior
I am suggesting that the first element is rendered with a "first-child" class and the last with a "last-child" class.

What is the motivation / use case for changing the behavior?
Would make styling lists easier.

  • Angular version: 2.0.0-rc.4
  • Browser: [all | Chrome XX | Firefox XX | IE XX | Safari XX | Mobile Chrome XX | Android X.X Web Browser | iOS XX Safari | iOS XX UIWebView | iOS XX WKWebView ]
  • Language: [all | TypeScript X.X | ES6/7 | ES5]
@dopatraman dopatraman changed the title Can we add "first-child" and "last-child" classes to ngFor Can we add "first-child" and "last-child" classes to ngFor? Aug 16, 2016
@sod
Copy link
Contributor

sod commented Aug 16, 2016

If that helps, you can already do this via:

  <div *ngFor="let item of items; let first = first; let last = last"
    [class.first-item]="first"
    [class.last-item]="last">
      {{ item }}
  </div>`

http://plnkr.co/edit/evR8YKXgvpYWqHgt8zZE?p=preview

@pkozlowski-opensource
Copy link
Member

Agree with @sod - the advantage is that it gives you full control over the CSS class name and doesn't require any changes to the framework.

Will close for now.

@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 9, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants