I am a beginner in typescript and believe that the issue I am facing is related to typescript. Currently, I am working on an Ionic app where I have a function setwall() being called from home.html. The setwall() function is defined in home.ts. However, when I run the Ionic app, it displays:
Runtime Error
Uncaught (in promise): TypeError: Cannot read property 'wallpaper' of undefined
TypeError: Cannot read property 'wallpaper' of undefined"
Below is the code from my home.ts file:
import { Component } from '@angular/core';
import { NavController, Platform } from 'ionic-angular';
import { ListPage } from '../list/list';
declare var window: any;
@Component({
selector: 'page-home',
templateUrl: 'home.html'
})
export class HomePage {
constructor(public navCtrl: NavController, private platform: Platform) {
}
goPage1() {
this.navCtrl.push(ListPage);
}
setwall() {
this.platform.ready().then(() => {
window['plugins'].wallpaper.setImage("assets/img/3.jpg");
});
}
}
Furthermore, here is the code from home.html:
<ion-header>
<ion-navbar>
<button ion-button menuToggle>
<ion-icon name="menu"></ion-icon>
</button>
<ion-title>Wallfeed</ion-title>
</ion-navbar>
</ion-header>
<ion-content class="card-background-page">
<ion-card (click)="goPage1()">
<img src="assets/img/1.png"/>
<div class="card-title">São Paulo</div>
<div class="card-subtitle">41 Listings</div>
</ion-card>
<ion-card>
<img src="assets/img/2.jpg"/>
<div class="card-title">Amsterdam</div>
<div class="card-subtitle">64 Listings</div>
</ion-card>
<ion-card (click)="setwall()">
<img src="assets/img/3.jpg"/>
<div class="card-title">San Francisco</div>
<div class="card-subtitle">72 Listings</div>
</ion-card>
<ion-card>
<img src="https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcQ16sUl5EqIDeuP1AjIX6ESSbAFAcS2-JLr4znf-extlfIr47Ni"/>
<div class="card-title">Madison</div>
<div class="card-subtitle">28 Listings</div>
</ion-card>
</ion-content>
If you need more information, please refer to the link for the cordova plugin: https://github.com/fbsanches/cordova-plugin-wallpaper Thank you.