fix(compiler): clone templates before compiling them
This is needed as the compiler changes templates during compilation and we are caching templates in the `TemplateLoader`. Closes #1058
This commit is contained in:
parent
f75a50c1dd
commit
9e8d31d532
modules/angular2
@ -39,7 +39,9 @@ export class TemplateLoader {
|
|||||||
StringMapWrapper.set(this._htmlCache, url, promise);
|
StringMapWrapper.set(this._htmlCache, url, promise);
|
||||||
}
|
}
|
||||||
|
|
||||||
return promise;
|
// We need to clone the result as others might change it
|
||||||
|
// (e.g. the compiler).
|
||||||
|
return promise.then( (tplElement) => DOM.clone(tplElement) );
|
||||||
}
|
}
|
||||||
|
|
||||||
throw new BaseException('View should have either the url or template property set');
|
throw new BaseException('View should have either the url or template property set');
|
||||||
|
@ -45,17 +45,19 @@ export function main() {
|
|||||||
xhr.flush();
|
xhr.flush();
|
||||||
}));
|
}));
|
||||||
|
|
||||||
it('should cache template loaded through XHR', inject([AsyncTestCompleter], (async) => {
|
it('should cache template loaded through XHR but clone it as the compiler might change it', inject([AsyncTestCompleter], (async) => {
|
||||||
var firstEl;
|
var firstEl;
|
||||||
|
// we have only one xhr.expect, so there can only be one xhr call!
|
||||||
xhr.expect('base/foo', 'xhr template');
|
xhr.expect('base/foo', 'xhr template');
|
||||||
var template = new ViewDefinition({absUrl: 'base/foo'});
|
var template = new ViewDefinition({absUrl: 'base/foo'});
|
||||||
loader.load(template)
|
loader.load(template)
|
||||||
.then((el) => {
|
.then((el) => {
|
||||||
|
expect(DOM.content(el)).toHaveText('xhr template');
|
||||||
firstEl = el;
|
firstEl = el;
|
||||||
return loader.load(template);
|
return loader.load(template);
|
||||||
})
|
})
|
||||||
.then((el) =>{
|
.then((el) =>{
|
||||||
expect(el).toBe(firstEl);
|
expect(el).not.toBe(firstEl);
|
||||||
expect(DOM.content(el)).toHaveText('xhr template');
|
expect(DOM.content(el)).toHaveText('xhr template');
|
||||||
async.done();
|
async.done();
|
||||||
});
|
});
|
||||||
|
Loading…
x
Reference in New Issue
Block a user