Isolate bootstrap CSS to one angular component?

☆樱花仙子☆ 提交于 2021-02-07 20:44:31

问题


Is it possible to isolate Bootstrap's css file to one Angular component?

When including the file globally in styles.css or in .angular-cli.json, the global styles are causing issues with other components that should not be using bootstrap. I have tried to do this by importing it from the component's CSS file but the styles do not seem to render properly...

I am using Angular 5 and Angular Cli 1.7.2.


回答1:


you can explicitly set the encapsulation strategy using the encapsulation property.Set it to ViewEncapsulation.Native for your case

@Component({
// ...
encapsulation: ViewEncapsulation.Native,
styles: [
  // ...
]
})
export class HelloComponent {
// ...
}

Native - styles from main HTML do not propagate to the component. Styles defined in this component's @Component decorator are scoped to this component only. Refer this View Encapsulation.



来源:https://stackoverflow.com/questions/49198651/isolate-bootstrap-css-to-one-angular-component

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!