angular-compiler-cli

window is undefined when used as useValue provider with Angular 4 AoT

风流意气都作罢 提交于 2019-11-27 07:00:48
问题 When Angular 4.0.2 application is compiled ahead-of-time, and the provider is defined as useValue import { OpaqueToken, Provider } from '@angular/core'; export const windowToken = new OpaqueToken('window'); export const windowProvider = { provide: windowToken, useValue: window }; and used like @NgModule({ providers: [windowProvider], ... }) export class AppModule {} it compiles ok but results in window being undefined when injected as constructor(@Inject(windowToken) window) { window

What does the angular compiler “compile”?

霸气de小男生 提交于 2019-11-27 05:05:24
问题 I was asked that today and was not able to give a proper answer. Typescript transpiles to JS. Then there is tree shaking, "less" (optional) and what else in the process of making a deployment. But nothing like that (afaik) has anything to do with "compiling". Everything gets bundled and heavily optimized, but it's not actually compiled, right? There is even an ahead of time compiler, which really does a noticeable job. What do I miss? Javascript itself is still intepreted, right? 回答1: You're