styleUrls not working in Angular 2 styleUrls not working in Angular 2 angular angular

styleUrls not working in Angular 2


You just need to remove the slash from the beginning of the styleUrls path like this:

@Component({    selector: 'dashboard',    templateUrl: '/app/components/dashboard/dashboard.html',    styleUrls: ['app/components/dashboard/dashboard.css']})


If you are using PrimeNG or Angular Material in your project that styleUrl will not work like this. You need to import ViewEncapsulation and put encapsulation: ViewEncapsulation.None in the @component definition.

import { Component, Output, Input, ViewEncapsulation} from '@angular/core';@Component({   encapsulation: ViewEncapsulation.None,   selector: 'message-center',   templateUrl: './messagecenter.component.html',   styleUrls: ['./messagecenter.component.css']})


Angular 2 docs say that SystemJS exposes __moduleName variable required for relative names just like module.id for CommonJS... Have you tried that?

declare var __moduleName: any;@Component({    moduleId: __moduleName,    selector: 'dashboard',    templateUrl: 'dashboard.html',    styleUrls: ['dashboard.css']})