diff --git a/packages/compiler/src/directive_normalizer.ts b/packages/compiler/src/directive_normalizer.ts index 2b7ec4b1754c0..ddc998fd5ee63 100644 --- a/packages/compiler/src/directive_normalizer.ts +++ b/packages/compiler/src/directive_normalizer.ts @@ -65,6 +65,10 @@ export class DirectiveNormalizer { let normalizedTemplateSync: CompileTemplateMetadata = null; let normalizedTemplateAsync: Promise; if (prenormData.template != null) { + if (prenormData.templateUrl != null) { + throw syntaxError( + `'${stringify(prenormData.componentType)}' component cannot define both template and templateUrl`); + } if (typeof prenormData.template !== 'string') { throw syntaxError( `The template specified for component ${stringify(prenormData.componentType)} is not a string`); diff --git a/packages/compiler/test/directive_normalizer_spec.ts b/packages/compiler/test/directive_normalizer_spec.ts index 58129dc917ce7..fa82051361f4b 100644 --- a/packages/compiler/test/directive_normalizer_spec.ts +++ b/packages/compiler/test/directive_normalizer_spec.ts @@ -51,6 +51,16 @@ export function main() { templateUrl: {} })).toThrowError('The templateUrl specified for component SomeComp is not a string'); })); + it('should throw if both template and templateUrl are defined', + inject([DirectiveNormalizer], (normalizer: DirectiveNormalizer) => { + expect(() => normalizer.normalizeTemplate({ + ngModuleType: null, + componentType: SomeComp, + moduleUrl: SOME_MODULE_URL, + template: '', + templateUrl: '', + })).toThrowError(`'SomeComp' component cannot define both template and templateUrl`); + })); }); describe('normalizeTemplateSync', () => {