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
|
|
|
|
*/
|
|
|
|
|
2017-05-18 16:46:51 -04:00
|
|
|
import {CompileReflector} from './compile_reflector';
|
2017-08-16 12:00:03 -04:00
|
|
|
import {NgModule, Type, createNgModule} from './core';
|
2017-03-01 17:10:59 -05:00
|
|
|
import {findLast} from './directive_resolver';
|
2017-08-16 12:00:03 -04:00
|
|
|
import {stringify} from './util';
|
2016-07-18 06:50:31 -04:00
|
|
|
|
|
|
|
|
|
|
|
/**
|
2016-09-12 22:14:17 -04:00
|
|
|
* Resolves types to {@link NgModule}.
|
2016-07-18 06:50:31 -04:00
|
|
|
*/
|
|
|
|
export class NgModuleResolver {
|
2017-05-18 16:46:51 -04:00
|
|
|
constructor(private _reflector: CompileReflector) {}
|
2016-07-18 06:50:31 -04:00
|
|
|
|
2017-08-16 12:00:03 -04:00
|
|
|
isNgModule(type: any) { return this._reflector.annotations(type).some(createNgModule.isTypeOf); }
|
2016-11-10 17:07:30 -05:00
|
|
|
|
2017-08-16 12:00:03 -04:00
|
|
|
resolve(type: Type, throwIfNotFound = true): NgModule|null {
|
|
|
|
const ngModuleMeta: NgModule =
|
|
|
|
findLast(this._reflector.annotations(type), createNgModule.isTypeOf);
|
2016-07-18 06:50:31 -04:00
|
|
|
|
2017-01-04 16:59:43 -05:00
|
|
|
if (ngModuleMeta) {
|
2016-07-18 06:50:31 -04:00
|
|
|
return ngModuleMeta;
|
|
|
|
} else {
|
|
|
|
if (throwIfNotFound) {
|
2016-08-25 03:50:16 -04:00
|
|
|
throw new Error(`No NgModule metadata found for '${stringify(type)}'.`);
|
2016-07-18 06:50:31 -04:00
|
|
|
}
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|