it('should not update existing compilation results', () => { viewResolver.setView( SomeComp, new ViewMetadata({template: '<child-cmp></child-cmp>', directives: [ChildComp]})); viewResolver.setInlineTemplate(ChildComp, 'oldChild'); let compFactory = compiler.compileComponentSync(SomeComp); viewResolver.setInlineTemplate(ChildComp, 'newChild'); compiler.compileComponentSync(SomeComp); let compRef = compFactory.create(injector); expect(compRef.location.nativeElement).toHaveText('oldChild'); });
fakeAsync(() => { @NgModule( {declarations: [SomeCompWithUrlTemplate], precompile: [SomeCompWithUrlTemplate]}) class SomeModule { } xhr.spy('get').andCallFake(() => Promise.resolve('hello')); compiler.compileModuleAsync(SomeModule); tick(); let ngModuleFactory = compiler.compileModuleSync(SomeModule); expect(ngModuleFactory).toBeTruthy(); }));
fakeAsync(() => { @NgModule({ declarations: [SomeCompWithUrlTemplate], entryComponents: [SomeCompWithUrlTemplate] }) class SomeModule { } resourceLoader.spy('get').and.callFake(() => Promise.resolve('hello')); compiler.compileModuleAsync(SomeModule); tick(); const ngModuleFactory = compiler.compileModuleSync(SomeModule); expect(ngModuleFactory).toBeTruthy(); }));
return new Promise<NgModuleFactory<{}>>((resolve, reject) => { // If module has been compiled AoT if (moduleOrFactory instanceof NgModuleFactory) { console.log('Already AoT?'); resolve(moduleOrFactory); return; } else { let moduleFactory = factoryCacheMap.get(moduleOrFactory); // If module factory is cached if (moduleFactory) { console.log('\n\n\n WE FOUND ONE!! USE IT!!\n\n\n'); resolve(moduleFactory); return; } // Compile the module and cache it compiler.compileModuleAsync(moduleOrFactory) .then((factory) => { console.log('\n\n\n\n MAP THIS THING!!!!\n\n\n '); factoryCacheMap.set(moduleOrFactory, factory); resolve(factory); }, (err => { reject(err); })); } });
.then((rawModule: any) => { const module = rawModule[ngModuleExport]; if (!module) { throw new Error(`Module ${modulePath} does not export ${ngModuleExport}`); } return compiler.compileModuleAsync(module); });
System.import('./dist/lazy.bundle.js').then((module: any) => { this.compiler.compileModuleAndAllComponentsAsync(module.LazyModule) .then((compiled) => { const factory = compiled.componentFactories[0]; this.container.createComponent(factory); }); });
return mergeMap.call(wrapIntoObservable(loadChildren()), (t: any) => { if (t instanceof NgModuleFactory) { return of (t); } else { return fromPromise(this.compiler.compileModuleAsync(t)); } });
fakeAsync(() => { xhr.spy('get').andCallFake(() => Promise.resolve('hello')); tcb.createFakeAsync(SomeCompWithUrlTemplate); let appModuleFactory = compiler.compileAppModuleSync( SomeModule, new AppModuleMetadata({precompile: [SomeCompWithUrlTemplate]})); expect(appModuleFactory).toBeTruthy(); }));
return wrapIntoObservable(loadChildren()).pipe(mergeMap((t: any) => { if (t instanceof NgModuleFactory) { return of (t); } else { return from(this.compiler.compileModuleAsync(t)); } }));
it('should allow to use templateUrl components', fakeAsync(() => { xhr.spy('get').andCallFake(() => Promise.resolve('hello')); let appModuleFactory: AppModuleFactory<any>; compiler .compileAppModuleAsync( SomeModule, new AppModuleMetadata({precompile: [SomeCompWithUrlTemplate]})) .then((f) => appModuleFactory = f); tick(); expect(appModuleFactory.moduleType).toBe(SomeModule); }));