typescript - How to import styles for ui custom library in angular 2? -


i working in ui library , have imported scss styles in components (button example). if instantiate component button twice in client app (my ui library dependency), scss calls twice too. there way, app client calls once button's scss?

now import scss in component example: have component "my-custom-button" my-custom-button.html, my-custom-button.scss , my-custom-button.ts . import scss file in my-custom-button.ts stylesurl.

what happening here ? angular uses component metaphore, each component has own view encapsulation. emulated default (see below meaning).

you can switch viewencapsulation mode setting encapsulation property 1 of these values :

  • viewencapsulation.none: no encapsulation done, component style apply element matching selector used in css.

  • viewencapsulation.emulated: angular rewrite components styles (adding custom attributes selectors) match related component , append inline <style> tag n head.

  • viewencapsulation.native: angular use native shadow dom of browser (won't work on old browsers).

example :

@component({    ...    encapsulation: viewencapsulation.native,    ... }) 

see component styles more details.

to conclude :

you can avoid evaluation on fly, putting styles in random css file puth in head of html, end of every components styles not being encapsulated.

maybe viewencapsulation.native more performant, have no proof neither , idea on how benchmark ( there a question related topic), , not work older browsers.


Comments

Popular posts from this blog

javascript - Clear button on addentry page doesn't work -

c# - Selenium Authentication Popup preventing driver close or quit -

tensorflow when input_data MNIST_data , zlib.error: Error -3 while decompressing: invalid block type -