diff --git a/packages/compiler-cli/test/ngtsc/ngtsc_spec.ts b/packages/compiler-cli/test/ngtsc/ngtsc_spec.ts index d04e2a590c..824ab3d8df 100644 --- a/packages/compiler-cli/test/ngtsc/ngtsc_spec.ts +++ b/packages/compiler-cli/test/ngtsc/ngtsc_spec.ts @@ -5155,13 +5155,16 @@ export const Foo = Foo__PRE_R3__; @Component({ selector: 'test', template: '', + styles: ['h2 {width: 10px}'] }) export class TestCmp {} `); env.driveMain(); const jsContents = env.getContents('test.js'); - expect(jsContents).toContain('styles: ["h1[_ngcontent-%COMP%] {font-size: larger}"]'); + expect(jsContents) + .toContain( + 'styles: ["h2[_ngcontent-%COMP%] {width: 10px}", "h1[_ngcontent-%COMP%] {font-size: larger}"]'); }); it('should process inline tags', () => { diff --git a/packages/compiler/src/jit_compiler_facade.ts b/packages/compiler/src/jit_compiler_facade.ts index 877501c14f..acd7502e9b 100644 --- a/packages/compiler/src/jit_compiler_facade.ts +++ b/packages/compiler/src/jit_compiler_facade.ts @@ -142,7 +142,7 @@ export class CompilerFacadeImpl implements CompilerFacade { selector: facade.selector || this.elementSchemaRegistry.getDefaultComponentElementName(), template, wrapDirectivesAndPipesInClosure: false, - styles: facade.styles || [], + styles: [...facade.styles, ...template.styles], encapsulation: facade.encapsulation as any, interpolation: interpolationConfig, changeDetection: facade.changeDetection, diff --git a/packages/core/test/acceptance/styling_spec.ts b/packages/core/test/acceptance/styling_spec.ts index 286e8fe726..c3e5874557 100644 --- a/packages/core/test/acceptance/styling_spec.ts +++ b/packages/core/test/acceptance/styling_spec.ts @@ -2410,6 +2410,33 @@ describe('styling', () => { .toEqual('url("https://i.imgur.com/4AiXzf8.jpg")'); }); }); + + isBrowser && it('should process +
+ `, + styles: [ + 'div { width: 100px; }', + ] + }) + class MyComp { + } + + TestBed.configureTestingModule({ + declarations: [MyComp], + }); + + const fixture = TestBed.createComponent(MyComp); + fixture.detectChanges(); + + // `styles` array values are applied first, styles from