I'm using AngularElements with native encapsulation so bs4 components can be used in bs3 project. Example:
@Component({
selector: 'app-my-button',
templateUrl: './my-button.component.html',
encapsulation: ViewEncapsulation.Native,
styles: ['@import "~bootstrap/scss/bootstrap.scss";']
})
export class MyButtonComponent {}
The question is how to change encapsulation of 3rd party component so that global css doesn't affect it? Given NgbModalWindow component. How to change its encapsulation to ViewEncapsulation.Native and apply particular styles?
Here is related issue
If you use a third party component inside a component whose
encapsulationis set to native, global styles wont apply to that third party component. E.g. If you use the third party componentngb-modal-windowinside your own component lets sayapp-my-own-componentwhose encapsulation is set to native, the global styles wont apply tongb-modal-windowbecause it will be inside shadow root(of the parentapp-my-own-component).However adding styles in
app-my-own-componentwill get applied tongb-modal-windowin this case.Another thing you can do is set
encapsulationtoViewEnacpsulation.Nativeat global level so that all components in you application will have Native encapsulation. You can do this while bootstrapping your app module in main.ts file:Change this:
platformBrowserDynamic().bootstrapModule(AppModule)to this:You will have to import
ViewEncapsulationinside main.ts of whatever the name of the file is where you are bootstrapping your module.