Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

how to combine 2 :host() from different css and different values for angular

I have two components for angular, I want to combine their css into one file but I am having a problem because the :host() is different from one another, for example:

style1.css contains:

:host() { flex: 2; overflow: auto; }

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

style2.css contains:

:host() { flex: 1; position: visible; }

is there any way for it to be combined?

>Solution :

You can specify your component with its selector along with host like the following:

combine.scss

:host(app-one) {
  color: 'green';
}

:host(app-two) {
  color: 'blue';
}

components

@Component({
  selector: 'app-one',
  template: `<h1>Hello</h1>`,
  styleUrls: ['./combine.scss']
})
export class ChildTwo {}

@Component({
  selector: 'app-two',
  template: `<h1>World</h1>`,
  styleUrls: ['./combine.scss']
})
export class ChildOne {}

parent component

<app-one></app-one>
<app-two></app-two>

The project structure would be something like:

 > child-one.component.ts
 > child-two.component.ts
 > parent-component.ts
 > combine.scss

Of course this is just an example, you probably have on separate folders, so make sure you specify the path correctly within styleUrls array

demo

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading