fix(core): don't override ngInjectableDef in the decorator if present on the type (#22943)

Previously, @Injectable() would generate an ngInjectableDef on the type it was
decorating, even if that type already had a compiled ngInjectableDef, overwriting
the compiled version.

PR Close #22943
This commit is contained in:
Alex Rickabaugh
2018-03-22 15:47:06 -07:00
committed by Matias Niemelä
parent 4f0cae0676
commit 6f0191744c
2 changed files with 20 additions and 1 deletions

View File

@ -119,7 +119,8 @@ export const Injectable: InjectableDecorator = makeDecorator(
'Injectable', undefined, undefined, undefined,
(injectableType: InjectableType<any>,
options: {providedIn?: Type<any>| 'root' | null} & InjectableProvider) => {
if (options && options.providedIn !== undefined) {
if (options && options.providedIn !== undefined &&
injectableType.ngInjectableDef === undefined) {
injectableType.ngInjectableDef = defineInjectable({
providedIn: options.providedIn,
factory: convertInjectableProviderToFactory(injectableType, options)