2016-07-18 06:50:31 -04:00
|
|
|
/**
|
|
|
|
* @license
|
|
|
|
* Copyright Google Inc. All Rights Reserved.
|
|
|
|
*
|
|
|
|
* Use of this source code is governed by an MIT-style license that can be
|
|
|
|
* found in the LICENSE file at https://angular.io/license
|
|
|
|
*/
|
|
|
|
|
2016-08-10 21:21:28 -04:00
|
|
|
import {Injectable, NgModuleMetadata, Type} from '@angular/core';
|
2016-07-18 06:50:31 -04:00
|
|
|
|
|
|
|
import {ReflectorReader, reflector} from '../core_private';
|
2016-08-10 21:21:28 -04:00
|
|
|
import {BaseException} from '../src/facade/exceptions';
|
|
|
|
import {isPresent, stringify} from './facade/lang';
|
2016-07-18 06:50:31 -04:00
|
|
|
|
|
|
|
function _isNgModuleMetadata(obj: any): obj is NgModuleMetadata {
|
|
|
|
return obj instanceof NgModuleMetadata;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Resolves types to {@link NgModuleMetadata}.
|
|
|
|
*/
|
|
|
|
@Injectable()
|
|
|
|
export class NgModuleResolver {
|
|
|
|
constructor(private _reflector: ReflectorReader = reflector) {}
|
|
|
|
|
2016-08-10 21:21:28 -04:00
|
|
|
resolve(type: Type<any>, throwIfNotFound = true): NgModuleMetadata {
|
2016-07-18 06:50:31 -04:00
|
|
|
const ngModuleMeta: NgModuleMetadata =
|
|
|
|
this._reflector.annotations(type).find(_isNgModuleMetadata);
|
|
|
|
|
|
|
|
if (isPresent(ngModuleMeta)) {
|
|
|
|
return ngModuleMeta;
|
|
|
|
} else {
|
|
|
|
if (throwIfNotFound) {
|
|
|
|
throw new BaseException(`No NgModule metadata found for '${stringify(type)}'.`);
|
|
|
|
}
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|