Skip to content

Commit 3871f89

Browse files
fix(ViewLoader): provide componentId in missing template / templateUrl errors
Befor this change it wasn't clear which component is faulty
1 parent d853d19 commit 3871f89

2 files changed

Lines changed: 9 additions & 5 deletions

File tree

‎modules/angular2/src/render/dom/compiler/view_loader.ts‎

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ export class ViewLoader {
3636
load(viewDef: ViewDefinition): Promise<TemplateAndStyles> {
3737
var r = wtfStartTimeRange('ViewLoader#load()', stringify(viewDef.componentId));
3838
let tplAndStyles: List<Promise<TemplateAndStyles>| Promise<string>| string> =
39-
[this._loadHtml(viewDef.template, viewDef.templateAbsUrl)];
39+
[this._loadHtml(viewDef.template, viewDef.templateAbsUrl, viewDef.componentId)];
4040
if (isPresent(viewDef.styles)) {
4141
viewDef.styles.forEach((cssText: string) => {
4242
let textOrPromise = this._resolveAndInlineCssText(cssText, viewDef.templateAbsUrl);
@@ -83,7 +83,8 @@ export class ViewLoader {
8383
}
8484

8585
// Load the html and inline any style tags
86-
private _loadHtml(template: string, templateAbsUrl: string): Promise<TemplateAndStyles> {
86+
private _loadHtml(template: string, templateAbsUrl: string,
87+
componentId: string): Promise<TemplateAndStyles> {
8788
let html;
8889

8990
// Load the HTML
@@ -92,7 +93,8 @@ export class ViewLoader {
9293
} else if (isPresent(templateAbsUrl)) {
9394
html = this._loadText(templateAbsUrl);
9495
} else {
95-
throw new BaseException('View should have either the templateUrl or template property set');
96+
throw new BaseException(
97+
`View should have either the templateUrl or template property set but none was found for the '${componentId}' component`);
9698
}
9799

98100
return html.then(html => {

‎modules/angular2/test/render/dom/compiler/view_loader_spec.ts‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,8 +83,10 @@ export function main() {
8383
}));
8484

8585
it('should throw when no template is defined', () => {
86-
expect(() => loader.load(new ViewDefinition({template: null, templateAbsUrl: null})))
87-
.toThrowError('View should have either the templateUrl or template property set');
86+
expect(() => loader.load(new ViewDefinition(
87+
{componentId: 'TestComponent', template: null, templateAbsUrl: null})))
88+
.toThrowError(
89+
'View should have either the templateUrl or template property set but none was found for the \'TestComponent\' component');
8890
});
8991

9092
it('should return a rejected Promise when XHR loading fails',

0 commit comments

Comments
 (0)