V
V
Vladimir Mirka2017-10-30 16:10:48
css
Vladimir Mirka, 2017-10-30 16:10:48

Angular2 - how not to lose the link of styles when connecting a component?

Essence of the question:

<div style="display: flex">
<app-component><!-- Внутри флекс элементы --></app-component>
</div>

In this case, the connection is lost and the flex element becomes <app-component>, and not what is inside.
Question: How to fix this? The component must remain a directive.

Answer the question

In order to leave comments, you need to log in

4 answer(s)
I
Ivan Stroykin, 2017-10-30
@flexaccess

<div>
    <app-component><!-- Внутри флекс элементы --></app-component>
</div>

...
@Component({
  selector: 'app-component',
  templateUrl: '...',
  host: {
    'class': 'app-flex-style'
  }
})
export class AppComponent {
  ....
}

and prescribe to the class .app-flex-style { display: flex } and everything else you need. No need to litter html, and you need to put everything on the shelves for easy manipulation of the application

S
Sasha Novik, 2017-10-31
@navix

There is one more option that can be useful in some cases (for example, when working with tables).
Add an attribute to the component selector:

...
@Component({
  selector: 'app-component,[appComponent]',
  templateUrl: '...',
})
export class AppComponent {
  ....
}

And then use it on the element:
<div appComponent style="display: flex">
  <!-- Внутри флекс элементы -->
</div>

A
Alexander Manakov, 2017-10-30
@gogolor

<div>
<app-component style="display: flex"><!-- Внутри флекс элементы --></app-component>
</div>

V
Vladimir, 2017-10-31
@Casufi

You can keep the project on https://c9.io/ and then you can edit it both on the iPad and on the Android tablet.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question