Converting an angular-based app (angular-cli) from a well-working JIT-based szenario to an AOT-based szenario. AOT-build is running fine.
On opening the resulting webpage i receive Cannot read property 'none' of undefined errors. Those errors result from undefined enums at runtime.
Very much simplified example (with 2 separate files)
action-type.enum.ts (enum in separate file)
export enum eActionType {
none,
actionA
...
}
test.component.ts (component in separate file)
import { eActionType } from './action-type.enum';
@Component({ ... })
export class Test {
// @Runtime eActionType (eActionType.none) will be undefined
private/protected/public actionType: eActionType = eActionType.none;
}
eActionType is not available withing test.component.ts although being imported.
Possible solution 1 - enum within same file (not desirable)
test.component.ts
// Exported enum within same file
export enum eActionType {
none,
actionA
...
}
@Component({ ... })
export class Test {
// @Runtime eActionType is available
private/protected/public actionType: eActionType = eActionType.none;
}
If the enum is declared within the same file, it will work properly at runtime. But that can't be desirable as one would loose maintainability compared to an enum within an external file that can be imported into several locations.
Possible solution 2 - class with static properties instead enum (not desirable either)
action-type.enum.ts (enum in separate file)
export class eActionType {
static none = 0;
static actionA = 1;
...
}
test.component.ts (component in separate file)
import { eActionType } from './action-type.enum';
@Component({ ... })
export class Test {
// @Runtime eActionType is available as static property of eActionType
private/protected/public actionType: eActionType = eActionType.none;
}
No really beautiful solution either, but at least only declaration of former enum, but not consumer-code has to be changed in all occurences.
How can i force a proper enum declared in an external file to be accessible in other locations at runtime?