In my angular 2 (RC5) project, I have a number of components, all of which work fine, however I added a submodule that works fine except for the styleUrl property of its childComponent. If I use the same URL path in the tutorial (the root component of the submodule), then the styles apply. If I add the same path to chapter (a child component of a submodule), will the styles not be applied?
There are no 404 blogs, and the hrome dev tools do not show chapter.css as a source or something present on the net.
Here you can see the component causing my problem:
@Component({ selector: 'chapter', template: `<div [innerHTML]="content"></div>`, styleUrls: ['app/tutorial/chapter/chapter.css'] }) export class chapterComponent implements OnInit, OnDestroy { private sub: Subscription; private content: string = ''; constructor( private route: ActivatedRoute) { } ngOnInit() { this.sub = this.route.params.subscribe(params => { var that = this; var _url = './chapter/' + params['id'] + '.html'; $.ajax({ url: _url, success: function (result) { that.content = result; } }); }); } }
chapter.css not chapter.css ... Here you can see my project files:
|-- error.html', |-- index.html', |-- app', |-- app.component.ts', |-- app.module.ts', |-- app.routes.ts', |-- main.ts', |-- home', | |-- home.component.ts', | |-- home.css', | |-- home.html', |-- tutorial', |-- tutorial.component.ts', |-- tutorial.css', |-- tutorial.html', |-- tutorial.module.ts', |-- tutorial.routes.ts', |-- chapter', |-- chapter.component.ts', |-- chapter.css', |-- chapter.html',
Why only this component does not work ... The only difference that I see is that this component is a child component, so maybe this made a difference?
Update:
As noted in the comments on the answers, using the ./app/tutorial/chapter/chapter.css path works in the tutorial component, but the same path does not work in the chapter component (which is a child component). I also added ViewEncapsulation, but that didn't work ...