UrlResolver

export class UrlResolver

exported from angular2/compiler defined in angular2/src/compiler/url_resolver.ts (line 24)

Used by the Compiler when resolving HTML and CSS template URLs.

This class can be overridden by the application developer to create custom behavior.

See Compiler

Example

class MyUrlResolver extends UrlResolver { resolve(baseUrl: string, url: string): string { // Serve CSS files from a special CDN. if (url.substr(-4) === '.css') { return super.resolve('http://cdn.myapp.com/css/', url); } return super.resolve(baseUrl, url); } } bootstrap(MyApp, [provide(UrlResolver, {useClass: MyUrlResolver})]);

Annotations

@Injectable()

Constructor

constructor(packagePrefix?: string)

Not Yet Documented

Members

resolve(baseUrl: string, url: string) : string

Resolves the url given the baseUrl:

  • when the url is null, the baseUrl is returned,
  • if url is relative ('path/to/here', './path/to/here'), the resolved url is a combination of baseUrl and url,
  • if url is absolute (it has a scheme: 'http://', 'https://' or start with '/'), the url is returned as is (ignoring the baseUrl)