1

I am currently adding bootstrap's container class to the component selector so all child elements react to bootsrap classes

for example in the index.html file i've applied

<app-root class="container"></app-root>

and in the bootstrapped app.component.html I've applied

<app-header class="row"></app-header>

Not sure if this is the recommended approach?

2 Answers 2

1

I recomend in app.component put the container class

<div class="container">

       <app-header></app-header>

</div>

and in the component app-header.component

<div class="row">
    ...
</div>
Sign up to request clarification or add additional context in comments.

Comments

-1

i am using angular4 Jquery plugin to add custom classes to components on creation with
jQuery('app-header').addClass('class1 class2 class3')

maybe you can use something like this in ngOnInit() or where it fits you best

Ex:

   import { Component, OnInit} from '@angular/core';
    @Component({
      selector: 'app-header',
      templateUrl: './app-component.html',
      styleUrls: ['./app-component.css']
    })
    export class AppComponent implements OnInit {
      ngOnInit(): void {
        jQuery('app-header').addClass('col-sm-6 example-class');
      }
    }

Then it should look something like this: <app-header class="col-sm-6 example-class"> ...

I do not know if this is the right way but it works for me for now

I hope it helps, Cheers

2 Comments

Unless there is a need to programmatically add a class to the 'app-root' as you've demonstrated in ngOnInit would it not be simpler and convenient to add the classes ''col-sm-6 example-class' to the 'app-root' selector directly?
i am using it like this for dynamically loaded components, i did not find another way for doing this so bootstrap will recognize cards added as angular modules for example(p.s.: i am using app-root selector in the example just to fit his case better)

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.