5

I'm learning Angular 2 and I wonder if it is possible to apply css style by using the component selector like this:

the component

@Component({
    selector: 'app',
    styleUrl: './local.css',
    templateUrl: './app.html',
})
export class AppComponent { }  

the style

app {
    width: 10px;
    height: 100px;
    background-color: red;
}

Assume it's possible, is it the best way to do that ?

1
  • What do you mean with "best way". Just do it. AFAIK component selector should work (never tried myself though) but :host is better practice because it aligns with how webcomponents are styled. Commented Oct 18, 2016 at 7:50

1 Answer 1

11

Use :host instead

:host {
    width: 10px;
    height: 100px;
    background-color: red;
}

Use app when you want to apply styles from outside the component.

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

1 Comment

Ok !! Thanks a lot :)

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.