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

@HostBinding can only set global css classes #11077

Closed
kemsky opened this issue Aug 25, 2016 · 6 comments
Closed

@HostBinding can only set global css classes #11077

kemsky opened this issue Aug 25, 2016 · 6 comments

Comments

@kemsky
Copy link

kemsky commented Aug 25, 2016

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

[x] bug report => search github for a similar issue or PR before submitting

Current behavior
Component:

...
    @HostBinding('class.small')
    private small:boolean = true;
...

Component style, private styles: ['...']:

.small {
    height: 100px !important;
}

Rendered:

<div class="small"></div>

And it does not have any effect obviously.

Expected/desired behavior

It should be possible to specify internal/private component class: :host.small

Please tell us about your environment:

  • Angular version: 2.0.0-rc.4
  • Browser: [all]
  • Language: [TypeScript 1.8.10]
@pkozlowski-opensource
Copy link
Member

You can use pseudo element selector :host to scope styles to the host element instead of its content: https://plnkr.co/edit/EPK3KnMGiCMs2ZTIYNT6?p=preview

In the future please:

@kemsky
Copy link
Author

kemsky commented Aug 25, 2016

For anybody who is interested, class has to be defined twice to be used with HostBinding and template:

:host.small, .small {
}

@zoechi
Copy link
Contributor

zoechi commented Aug 26, 2016

Should be :host(.small) {}

@kemsky
Copy link
Author

kemsky commented Aug 26, 2016

@zoechi, it does not work:

:host(.small) {
    height: 60px !important;
}
//==> host only, :host(.small) and :host.small render the same css
[_nghost-edd-26].small {
    height: 60px !important;
}

vs

:host.small, .small {
    height: 60px !important;
}
//==> host and template
[_nghost-ykl-22].small, .small[_ngcontent-ykl-22] {
    height: 60px !important;
}

@zoechi
Copy link
Contributor

zoechi commented Aug 26, 2016

Please provide a Plunker that demonstrates the actual behavior and explain what behavior you expect.

@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