/
Relative paths for templates and css in angular2
Relative paths for templates and css in angular2
Problem
The relative paths do not work in @Component. For example:
@Component({ selector: 'datepicker-popup', directives: [], providers: [], templateUrl: './datepicker.comp.html', styleUrls: ['./datepicker.css'] })
The templateUrl and styleUrls will not point to their relative locations.
Solution
For Angular2 Beta version:
My app is using SystemJS, so the solution is adding moduleId: __moduleName in the Component decorator.
The solution to the above example:
@Component({ selector: 'datepicker-popup', moduleId: __moduleName, directives: [], providers: [], templateUrl: './datepicker.comp.html', styleUrls: ['./datepicker.css'] })
Here is my tsconfig.json:
{ "compilerOptions": { "target": "es5", "module": "system", "moduleResolution": "node", "sourceMap": true, "emitDecoratorMetadata": true, "experimentalDecorators": true, "removeComments": true, "noImplicitAny": false }, "exclude": ["node_modules"] }
The module has been set as system.
Here is the updated solution for AngularJS 2 RC:
@Component({ selector: 'datepicker-popup', moduleId: module.id, providers: [], templateUrl: './datepicker.comp.html', styleUrls: ['./datepicker.css'] })
tsconfig.json
{ "compilerOptions": { "target": "es5", "module": "commonjs", "moduleResolution": "node", "sourceMap": true, "emitDecoratorMetadata": true, "experimentalDecorators": true, "removeComments": true, "noImplicitAny": false }, "exclude": [ "node_modules" ] }
Related articles
http://blog.thoughtram.io/angular/2016/06/08/component-relative-paths-in-angular-2.html
, multiple selections available,
Related content
CMS Project Landing Page
CMS Project Landing Page
More like this
Multiple NTPs for On-Call Contracts
Multiple NTPs for On-Call Contracts
More like this
NTP Tab
NTP Tab
More like this
Document
Document
More like this
Reminder Panel
Reminder Panel
More like this
City Working Days (CWD)
City Working Days (CWD)
More like this