xiaoke
xiaoke

Reputation: 3441

Angular 2, class attribute for customized component

Is the class attribute useful in angular 2 for a customized component? For example:

<app-my-first-component class='darkBackground'></app-my-first-component>

It looks like the class does not affect the component.

Upvotes: 2

Views: 93

Answers (2)

G&#252;nter Z&#246;chbauer
G&#252;nter Z&#246;chbauer

Reputation: 657406

You can address the class by adding a style to app-my-first-component like

@Component({
  ...,
 styles: [`
  :host(.darkBackground) {
    color: white;
    background-color: darkgrey;
  }`]
})

Upvotes: 1

Xilbreks
Xilbreks

Reputation: 157

Yes, you can use class attribute. And, there is another way to do the same, using host attribute.

@Component({
selector: 'app-my-first-component',
host: {'class':'darkBackground'}
})

Upvotes: 1

Related Questions