import { Component , OnInit } from '@angular/core' ; import { HttpClient } from '@angular/common/http' ; import { Router } from '@angular/router' ; @ Component ( { selector : 'app-home' , templateUrl : 'home.page.html' , styleUrls : [ 'home.page.scss' ] , } ) export class HomePage implements OnInit { deferredPrompt : any ; showInstallBtn : boolean = true ; pwa_features : any ; constructor ( private http , private router ) { window . addEventListener ( 'beforeinstallprompt' , ( e ) => { console . log ( 'beforeinstallprompt Event fired' ) ; e . preventDefault ( ) ; this . deferredPrompt = e ; this . showInstallBtn = true ; } ) ; } ngOnInit ( ) { this . http . get ( "/assets/data.json" ) . subscribe ( res => this . pwa_features = res [ "pwa_features" ] ) ; if ( this . deferredPrompt === undefined ) { this . showInstallBtn = false ; } } showInstallBanner ( ) { if ( this . deferredPrompt !== undefined && this . deferredPrompt !== null ) { this . deferredPrompt . prompt ( ) ; this . deferredPrompt . userChoice . then ( ( choiceResult ) => { if ( choiceResult . outcome === 'accepted' ) { console . log ( 'User accepted the A2HS prompt' ) ; } else { console . log ( 'User dismissed the A2HS prompt' ) ; } this . deferredPrompt = null ; } ) ; } } goToDetailsView ( item ) { this . router . navigate ( [ "/details" , item . slug ] ) ; } }