Skip to content

Instantly share code, notes, and snippets.

@LayZeeDK
Last active February 17, 2020 05:09
Show Gist options
  • Save LayZeeDK/2cd1ff1fc605af6f578a39311b3aba99 to your computer and use it in GitHub Desktop.
Save LayZeeDK/2cd1ff1fc605af6f578a39311b3aba99 to your computer and use it in GitHub Desktop.
Angular Ivy detection logic.
import {
Type,
ɵNG_COMP_DEF,
ɵNG_DIR_DEF,
ɵNG_MOD_DEF,
ɵNG_PIPE_DEF,
} from '@angular/core';
function isIvy(): boolean {
const ng: any = ((self || global || window) as any).ng;
return ng === undefined
|| ng.getComponent !== undefined
|| ng.applyChanges !== undefined;
}
function isIvyComponent(componentType: Type<any>): boolean {
return (componentType as any)[ɵNG_COMP_DEF] !== undefined;
}
function isIvyDirective(directiveType: Type<any>): boolean {
return (directiveType as any)[ɵNG_DIR_DEF] !== undefined;
}
function isIvyModule(moduleType: Type<any>): boolean {
return (moduleType as any)[ɵNG_MOD_DEF] !== undefined;
}
function isIvyPipe(pipeType: Type<any>): boolean {
return (pipeType as any)[ɵNG_PIPE_DEF] !== undefined;
}
@BioPhoton
Copy link

See, it was too late. haha.

Thanks! Updated it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment