@angular/material styles in a single stylesheet










1














I want to move all the styles into a single stylesheet, no individual component styles. I can control my styles, however when I include @angular/material components, they are added as individual style tags:



Renders



I have a single styles.scss file, which already includes the material designs according to the docu.



// Include the default theme styles.
@include angular-material-theme($candy-app-theme);


How can I also add all the components into the single stylesheet?



Edit: this is how the @angular/material modules are added:



import NgModule from '@angular/core';
import
MatButtonModule,
MatGridListModule,
MatIconModule,
MatListModule,
MatSidenavModule,
MatToolbarModule,
from '@angular/material';

@NgModule(
exports: [
MatButtonModule,
MatGridListModule,
MatIconModule,
MatListModule,
MatSidenavModule,
MatToolbarModule,
]
)
export class MaterialModule









share|improve this question























  • this sounds like @import ?
    – Mike
    Nov 15 '18 at 12:43











  • Yes, the styles are imported via '@include angular-material-theme($candy-app-theme);' which should add all components to the stylesheet. However the styles are still done via adding style tags
    – Stefan
    Nov 15 '18 at 12:51










  • Besides global styles material also uses local styles through styleUrls like github.com/angular/material2/blob/… So they are added as inline styles
    – yurzui
    Nov 15 '18 at 13:11







  • 1




    @Mike take.ms/IWhoM
    – yurzui
    Nov 15 '18 at 14:10






  • 2




    github.com/angular/angular-cli/issues/…
    – yurzui
    Nov 15 '18 at 14:22















1














I want to move all the styles into a single stylesheet, no individual component styles. I can control my styles, however when I include @angular/material components, they are added as individual style tags:



Renders



I have a single styles.scss file, which already includes the material designs according to the docu.



// Include the default theme styles.
@include angular-material-theme($candy-app-theme);


How can I also add all the components into the single stylesheet?



Edit: this is how the @angular/material modules are added:



import NgModule from '@angular/core';
import
MatButtonModule,
MatGridListModule,
MatIconModule,
MatListModule,
MatSidenavModule,
MatToolbarModule,
from '@angular/material';

@NgModule(
exports: [
MatButtonModule,
MatGridListModule,
MatIconModule,
MatListModule,
MatSidenavModule,
MatToolbarModule,
]
)
export class MaterialModule









share|improve this question























  • this sounds like @import ?
    – Mike
    Nov 15 '18 at 12:43











  • Yes, the styles are imported via '@include angular-material-theme($candy-app-theme);' which should add all components to the stylesheet. However the styles are still done via adding style tags
    – Stefan
    Nov 15 '18 at 12:51










  • Besides global styles material also uses local styles through styleUrls like github.com/angular/material2/blob/… So they are added as inline styles
    – yurzui
    Nov 15 '18 at 13:11







  • 1




    @Mike take.ms/IWhoM
    – yurzui
    Nov 15 '18 at 14:10






  • 2




    github.com/angular/angular-cli/issues/…
    – yurzui
    Nov 15 '18 at 14:22













1












1








1







I want to move all the styles into a single stylesheet, no individual component styles. I can control my styles, however when I include @angular/material components, they are added as individual style tags:



Renders



I have a single styles.scss file, which already includes the material designs according to the docu.



// Include the default theme styles.
@include angular-material-theme($candy-app-theme);


How can I also add all the components into the single stylesheet?



Edit: this is how the @angular/material modules are added:



import NgModule from '@angular/core';
import
MatButtonModule,
MatGridListModule,
MatIconModule,
MatListModule,
MatSidenavModule,
MatToolbarModule,
from '@angular/material';

@NgModule(
exports: [
MatButtonModule,
MatGridListModule,
MatIconModule,
MatListModule,
MatSidenavModule,
MatToolbarModule,
]
)
export class MaterialModule









share|improve this question















I want to move all the styles into a single stylesheet, no individual component styles. I can control my styles, however when I include @angular/material components, they are added as individual style tags:



Renders



I have a single styles.scss file, which already includes the material designs according to the docu.



// Include the default theme styles.
@include angular-material-theme($candy-app-theme);


How can I also add all the components into the single stylesheet?



Edit: this is how the @angular/material modules are added:



import NgModule from '@angular/core';
import
MatButtonModule,
MatGridListModule,
MatIconModule,
MatListModule,
MatSidenavModule,
MatToolbarModule,
from '@angular/material';

@NgModule(
exports: [
MatButtonModule,
MatGridListModule,
MatIconModule,
MatListModule,
MatSidenavModule,
MatToolbarModule,
]
)
export class MaterialModule






angular angular-material






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 15 '18 at 12:54

























asked Nov 12 '18 at 23:34









Stefan

9,8251057105




9,8251057105











  • this sounds like @import ?
    – Mike
    Nov 15 '18 at 12:43











  • Yes, the styles are imported via '@include angular-material-theme($candy-app-theme);' which should add all components to the stylesheet. However the styles are still done via adding style tags
    – Stefan
    Nov 15 '18 at 12:51










  • Besides global styles material also uses local styles through styleUrls like github.com/angular/material2/blob/… So they are added as inline styles
    – yurzui
    Nov 15 '18 at 13:11







  • 1




    @Mike take.ms/IWhoM
    – yurzui
    Nov 15 '18 at 14:10






  • 2




    github.com/angular/angular-cli/issues/…
    – yurzui
    Nov 15 '18 at 14:22
















  • this sounds like @import ?
    – Mike
    Nov 15 '18 at 12:43











  • Yes, the styles are imported via '@include angular-material-theme($candy-app-theme);' which should add all components to the stylesheet. However the styles are still done via adding style tags
    – Stefan
    Nov 15 '18 at 12:51










  • Besides global styles material also uses local styles through styleUrls like github.com/angular/material2/blob/… So they are added as inline styles
    – yurzui
    Nov 15 '18 at 13:11







  • 1




    @Mike take.ms/IWhoM
    – yurzui
    Nov 15 '18 at 14:10






  • 2




    github.com/angular/angular-cli/issues/…
    – yurzui
    Nov 15 '18 at 14:22















this sounds like @import ?
– Mike
Nov 15 '18 at 12:43





this sounds like @import ?
– Mike
Nov 15 '18 at 12:43













Yes, the styles are imported via '@include angular-material-theme($candy-app-theme);' which should add all components to the stylesheet. However the styles are still done via adding style tags
– Stefan
Nov 15 '18 at 12:51




Yes, the styles are imported via '@include angular-material-theme($candy-app-theme);' which should add all components to the stylesheet. However the styles are still done via adding style tags
– Stefan
Nov 15 '18 at 12:51












Besides global styles material also uses local styles through styleUrls like github.com/angular/material2/blob/… So they are added as inline styles
– yurzui
Nov 15 '18 at 13:11





Besides global styles material also uses local styles through styleUrls like github.com/angular/material2/blob/… So they are added as inline styles
– yurzui
Nov 15 '18 at 13:11





1




1




@Mike take.ms/IWhoM
– yurzui
Nov 15 '18 at 14:10




@Mike take.ms/IWhoM
– yurzui
Nov 15 '18 at 14:10




2




2




github.com/angular/angular-cli/issues/…
– yurzui
Nov 15 '18 at 14:22




github.com/angular/angular-cli/issues/…
– yurzui
Nov 15 '18 at 14:22












1 Answer
1






active

oldest

votes


















0





+100









A call to the angular-material-theme() mixin will include theming only for components plus core (global) styles. Angular Material component style that is not part of theming is encapsulated and built in to the component and dynamically added to the DOM. There is no way to automatically include those styles in a single stylesheet. Even if you could do that, it is possible that everything might not work properly, plus you would also need to turn off the style tags inserted into the DOM by the components, which isn't possible. Furthermore, since the components themselves already contain the style code, you would be adding a lot of size to the page by duplicating the style in a global stylesheet. In other words, you can't do it and it shouldn't be done.






share|improve this answer




















  • Disappointing but ok
    – Stefan
    Nov 18 '18 at 22:57










Your Answer






StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");

StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);

else
createEditor();

);

function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);



);













draft saved

draft discarded


















StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53271642%2fangular-material-styles-in-a-single-stylesheet%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes









0





+100









A call to the angular-material-theme() mixin will include theming only for components plus core (global) styles. Angular Material component style that is not part of theming is encapsulated and built in to the component and dynamically added to the DOM. There is no way to automatically include those styles in a single stylesheet. Even if you could do that, it is possible that everything might not work properly, plus you would also need to turn off the style tags inserted into the DOM by the components, which isn't possible. Furthermore, since the components themselves already contain the style code, you would be adding a lot of size to the page by duplicating the style in a global stylesheet. In other words, you can't do it and it shouldn't be done.






share|improve this answer




















  • Disappointing but ok
    – Stefan
    Nov 18 '18 at 22:57















0





+100









A call to the angular-material-theme() mixin will include theming only for components plus core (global) styles. Angular Material component style that is not part of theming is encapsulated and built in to the component and dynamically added to the DOM. There is no way to automatically include those styles in a single stylesheet. Even if you could do that, it is possible that everything might not work properly, plus you would also need to turn off the style tags inserted into the DOM by the components, which isn't possible. Furthermore, since the components themselves already contain the style code, you would be adding a lot of size to the page by duplicating the style in a global stylesheet. In other words, you can't do it and it shouldn't be done.






share|improve this answer




















  • Disappointing but ok
    – Stefan
    Nov 18 '18 at 22:57













0





+100







0





+100



0




+100




A call to the angular-material-theme() mixin will include theming only for components plus core (global) styles. Angular Material component style that is not part of theming is encapsulated and built in to the component and dynamically added to the DOM. There is no way to automatically include those styles in a single stylesheet. Even if you could do that, it is possible that everything might not work properly, plus you would also need to turn off the style tags inserted into the DOM by the components, which isn't possible. Furthermore, since the components themselves already contain the style code, you would be adding a lot of size to the page by duplicating the style in a global stylesheet. In other words, you can't do it and it shouldn't be done.






share|improve this answer












A call to the angular-material-theme() mixin will include theming only for components plus core (global) styles. Angular Material component style that is not part of theming is encapsulated and built in to the component and dynamically added to the DOM. There is no way to automatically include those styles in a single stylesheet. Even if you could do that, it is possible that everything might not work properly, plus you would also need to turn off the style tags inserted into the DOM by the components, which isn't possible. Furthermore, since the components themselves already contain the style code, you would be adding a lot of size to the page by duplicating the style in a global stylesheet. In other words, you can't do it and it shouldn't be done.







share|improve this answer












share|improve this answer



share|improve this answer










answered Nov 16 '18 at 21:31









G. Tranter

4,1011223




4,1011223











  • Disappointing but ok
    – Stefan
    Nov 18 '18 at 22:57
















  • Disappointing but ok
    – Stefan
    Nov 18 '18 at 22:57















Disappointing but ok
– Stefan
Nov 18 '18 at 22:57




Disappointing but ok
– Stefan
Nov 18 '18 at 22:57

















draft saved

draft discarded
















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid


  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.





Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


Please pay close attention to the following guidance:


  • Please be sure to answer the question. Provide details and share your research!

But avoid


  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53271642%2fangular-material-styles-in-a-single-stylesheet%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

27

Top Tejano songwriter Luis Silva dead of heart attack at 64

Category:Rhetoric