2017-10-02 1 views
1

Je suis nouveau à tapuscrit. Je pense que ce problème a à voir avec le tapuscrit. Je construis une application ionique. J'appelle une fonction setwall() de home.html. J'ai défini la fonction setwall() dans home.ts. Lorsque je cours l'application ionique montreTypecript TypeError: Impossible de lire la propriété de undefined

Runtime Error 
Uncaught (in promise): TypeError: Cannot read property 'wallpaper' of undefined TypeError: Cannot read property 'wallpaper' of undefined" 

Ceci est mon code de home.ts.

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"); 
}); 
} 
} 

également pour plus d'informations: Voici le code 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> 

Lien vers plugin cordova: https://github.com/fbsanches/cordova-plugin-wallpaper Merci.

+0

'window.plugins' est' undefined' – evolutionxbox

+0

serait-il le prendre trop loin pour dire: quelqu'un donner ce gars^une médaille – Dellirium

+0

@Dellirium \\ _ ¯ (ツ) _/¯ – evolutionxbox

Répondre

1

Vous pouvez essayer comme indiqué ci-dessous.

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"); //Changed here 
    }); 
} 
}