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