2021-12-10 02:37:01 +00:00
|
|
|
/**
|
|
|
|
|
* @license
|
|
|
|
|
* Copyright Google LLC 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
|
|
|
|
|
*/
|
|
|
|
|
|
2020-02-07 18:39:15 +00:00
|
|
|
declare const ng: any;
|
|
|
|
|
|
|
|
|
|
export const appIsAngularInDevMode = (): boolean => {
|
|
|
|
|
return appIsAngular() && appHasGlobalNgDebugObject();
|
|
|
|
|
};
|
|
|
|
|
|
2020-04-20 17:13:18 +00:00
|
|
|
export const appIsAngularIvy = (): boolean => {
|
2021-04-16 22:39:16 +00:00
|
|
|
return typeof (window as any).getAllAngularRootElements?.()?.[0]?.__ngContext__ !== 'undefined';
|
2020-04-20 17:13:18 +00:00
|
|
|
};
|
|
|
|
|
|
2020-02-07 18:39:15 +00:00
|
|
|
export const appIsAngular = (): boolean => {
|
|
|
|
|
return !!getAngularVersion();
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
export const appIsSupportedAngularVersion = (): boolean => {
|
2020-03-11 00:47:49 +00:00
|
|
|
const version = getAngularVersion();
|
2020-03-20 18:54:37 +00:00
|
|
|
if (!version) {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
2020-03-11 00:47:49 +00:00
|
|
|
const major = parseInt(version.toString().split('.')[0], 10);
|
2022-05-05 00:03:02 +00:00
|
|
|
return appIsAngular() && (major >= 12 || major === 0);
|
2020-02-07 18:39:15 +00:00
|
|
|
};
|
|
|
|
|
|
2021-04-29 17:23:49 +00:00
|
|
|
/**
|
|
|
|
|
* We check if the global `window.ng` is an object and if this object
|
2021-05-23 17:48:21 +00:00
|
|
|
* has the `getComponent` or `probe` methods attached to it.
|
|
|
|
|
*
|
|
|
|
|
* `ng.probe` is a view engine method, but to ensure that we correctly
|
|
|
|
|
* detect development mode we need to consider older rendering engines.
|
|
|
|
|
*
|
|
|
|
|
* In some g3 apps processed with Closure, `ng` is a function,
|
|
|
|
|
* which means that `typeof ng !== 'undefined'` is not a sufficient check.
|
2021-04-29 17:23:49 +00:00
|
|
|
*
|
|
|
|
|
* @returns if the app has global ng debug object
|
|
|
|
|
*/
|
2020-02-07 18:39:15 +00:00
|
|
|
const appHasGlobalNgDebugObject = (): boolean => {
|
2021-12-09 05:44:17 +00:00
|
|
|
return typeof ng === 'object' &&
|
|
|
|
|
(typeof ng.getComponent === 'function' || typeof ng.probe === 'function');
|
2020-02-07 18:39:15 +00:00
|
|
|
};
|
|
|
|
|
|
2021-12-09 05:44:17 +00:00
|
|
|
export const getAngularVersion = (): string|null => {
|
2020-02-07 18:39:15 +00:00
|
|
|
const el = document.querySelector('[ng-version]');
|
|
|
|
|
if (!el) {
|
2020-04-20 17:13:18 +00:00
|
|
|
return null;
|
2020-02-07 18:39:15 +00:00
|
|
|
}
|
|
|
|
|
return el.getAttribute('ng-version');
|
|
|
|
|
};
|