Theme/style Angular 2 reusable component libraries

邮差的信 提交于 2019-12-03 09:15:19

Try this way:

  1. Add scss styles folder to project
  2. Add to build task - copy styles folder to 'dist' folder
  3. install your npm package to client project (npm i )
  4. Import styles from node_modules, SASS/SCSS says it should start with ~; you should @import '~/dist/scss/somefile to project scss file.

What I've tried in this context (note that I'm using Angular v6):

For example you are calling in app.component.html

If your app.component.css or app.component.scss contains the styling that should be applied in ,

Set the viewEncapsulation for the component to none in your app.component.ts:

import { ViewEncapsulation } from '@angular/core';

@Component({
  selector: 'app-root',
  templateUrl: './app.component.html',
  styleUrls: ['./app.component.css'],
  encapsulation: ViewEncapsulation.None
})

Which will allow all your styling that you have in your app.component.(s)css to flow beyond to reach the library you are using.

This quick fix is what made component styling go beyond the current component and be applied to the libraries used.

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