Shared styles across components in an Angular 2 app

后端 未结 2 565
梦谈多话
梦谈多话 2020-12-14 00:02

I\'ve got some CSS rules in my Angular 2 app that would be common across various components. Obviously I don\'t want to copy&paste them into each component\'s styles. I

2条回答
  •  余生分开走
    2020-12-14 00:59

    There are 3 ways to use styling in angular2 app (link). You have mentioned two of those that allows you to reuse styles.

    My personal opinion is that for any large application its preferable to go with #2 mainly due to the view encapsulation provided by angular.

    #1 can be used for the really very generic styles that are common to all parts of your application. But if you will take into account that the root in your SPA will be angular component anyway - there is no real need to go with another approach of linking styles than #2.

    Moreover by working with css in two different ways you will have to remember this (and handle with some extra code) when for example bundling your app and using tools like gulp-inline-ng2-template

提交回复
热议问题