feat(PrivateComponentLoader): Explicit error message when loading a non-component

fixes #1062
This commit is contained in:
Victor Berchet
2015-03-24 09:34:47 +01:00
parent 65d759316b
commit 101a4aa3cf
2 changed files with 39 additions and 1 deletions

View File

@ -2,8 +2,9 @@ import {Compiler} from './compiler';
import {ShadowDomStrategy} from './shadow_dom_strategy';
import {EventManager} from 'angular2/src/core/events/event_manager';
import {DirectiveMetadataReader} from 'angular2/src/core/compiler/directive_metadata_reader';
import {Component} from 'angular2/src/core/annotations/annotations';
import {PrivateComponentLocation} from './private_component_location';
import {Type} from 'angular2/src/facade/lang';
import {Type, stringify, BaseException} from 'angular2/src/facade/lang';
export class PrivateComponentLoader {
@ -23,6 +24,11 @@ export class PrivateComponentLoader {
load(type:Type, location:PrivateComponentLocation) {
var annotation = this.directiveMetadataReader.read(type).annotation;
if (!(annotation instanceof Component)) {
throw new BaseException(`Could not load '${stringify(type)}' because it is not a component.`);
}
return this.compiler.compile(type).then((componentProtoView) => {
location.createComponent(
type, annotation,