fix(angular): platform does not crash

fixes #15348
This commit is contained in:
Manu Mtz.-Almeida
2018-08-29 01:23:31 +02:00
parent 6fdeb319ef
commit 82f9fd4ce7

View File

@ -18,7 +18,7 @@ export const PLATFORMS_MAP = {
export type Platforms = keyof typeof PLATFORMS_MAP;
export function getPlatforms(win: any) {
return win.Ionic.platforms;
return setupPlatforms(win);
}
export function isPlatform(win: Window, platform: Platforms) {
@ -26,12 +26,15 @@ export function isPlatform(win: Window, platform: Platforms) {
}
export function setupPlatforms(win: any) {
win.Ionic = win.Ionic || {};
let platforms: string[] = win.Ionic.platforms;
if (platforms == null) {
platforms = win.Ionic.platforms = detectPlatforms(win);
const classList = win.document.documentElement.classList;
platforms.forEach(p => classList.add(`plt-${p}`));
}
return platforms;
}
function detectPlatforms(win: Window): string[] {