feat(compiler): Support $baseUrl in HTML attributes when loading a template.
Angular fetches template HTML files outside of the browser's normal parsing flow. As a result, URLs in template files are interpreted relative to the root application, when the components defined by the template files are inserted into the DOM. This change enables a template author to prefix URLs with the string $baseUrl, which will be replaced with the relative base path of the template file. So for an example template loaded from /component/foo/template.html: <img src="$baseUrl/logo.png" /> becomes: <img src="/component/foo/logo.png" /> Addresses #2384.
This commit is contained in:
@@ -118,6 +118,16 @@ export function main() {
|
||||
});
|
||||
xhr.flush();
|
||||
}));
|
||||
it('should replace $baseUrl in attributes with the template base url',
|
||||
inject([AsyncTestCompleter], (async) => {
|
||||
xhr.expect('http://ng.io/path/foo.html', '<img src="$baseUrl/logo.png">');
|
||||
var view = new ViewDefinition({templateAbsUrl: 'http://ng.io/path/foo.html'});
|
||||
loader.load(view).then((el) => {
|
||||
expect(DOM.getInnerHTML(el)).toEqual('<img src="http://ng.io/path/logo.png">');
|
||||
async.done();
|
||||
});
|
||||
xhr.flush();
|
||||
}));
|
||||
});
|
||||
|
||||
describe('css', () => {
|
||||
|
||||
Reference in New Issue
Block a user