Angular 2 resolve base path from root instead of current path when using templateUrl

I have an Angular 2 app and I am using the old one templateUrl

to load an HTML template from a url on the same server.

templateUrl: '/components/directive/directive.html'

      

I am on the path /loaded/path/

where my directive is being loaded.

It worked fine in Angular 1, but in Angular 2 it throws this error

Could not resolve the url /components/directive/directive.html from http://example.com/loaded/path/
Error
    at new BaseException (http://example.com/angular2.sfx.dev.js:10986:25)
    at UrlResolver.System.register.execute.UrlResolver.resolve

      

I suppose one solution is to add ../../

templateUrl: '../../components/directive/directive.html'

      

but what if i'm at /some/other/loaded/path

where i use my directive

Is there a way to tell Angular 2 to resolve the path from the root and not the current path?

+3


source to share





All Articles