Reputation: 352
I have developed a library in an angular application (which is generated using angular cli) and the library contains a component with its own template file and stylesheet. However, when I load the module in the app.module.ts
and run the app (using ng serve for simplicity), the styles within the stylesheet are not rendered.
ng generate library
projects
directory of the app<name of the component>/src/lib
directoryThe app.module.ts
file contains the following code:
import { BrowserModule } from '@angular/platform-browser';
import { NgModule } from '@angular/core';
import { AppComponent } from './app.component';
import { GuitarChordGeneratorModule } from 'projects/guitar-chord-generator/src/public-api';
@NgModule({
declarations: [
AppComponent
],
imports: [
BrowserModule,
GuitarChordGeneratorModule
],
providers: [],
bootstrap: [AppComponent]
})
export class AppModule { }
Below is a snippet from the guitar-chord-generator.component.ts
file:
import { Component, OnInit, Input } from '@angular/core';
import { Chord } from './chord';
import { GCSGConfig } from './gcsgconfig';
@Component({
selector: 'lib-guitar-chord-generator',
templateUrl: './guitar-chord-generator.component.html',
styles: ['./guitar-chord-generator.component.css']
})
The image below is the directory structure of the app.
As you can see that guitar-chord-generator.component.css
is the CSS file for the component.
Upvotes: 0
Views: 1919
Reputation: 8492
Your component has
styles: ['./guitar-chord-generator.component.css']
The styles property takes an array of strings that contain CSS code.
You should be using styleUrls
styleUrls: ['./guitar-chord-generator.component.css']
Upvotes: 3