2016-10-21 146 views
1

從下面的Ionic 2頁面可以找到一個從服務中提取數據並立即變得毫無依據的頁面,我無法在設備,模擬器甚至是瀏覽器上點擊任何東西。Ionic 2頁面無響應

home.html的

<ion-header> 
    <ion-navbar hideBackButton="true" danger> 
    <button menuToggle> 
     <ion-icon name="menu"></ion-icon> 
    </button> 
    <ion-title>Shoppa</ion-title> 
    </ion-navbar> 
</ion-header> 

<ion-content class="cards-bg social-cards"> 

    <ion-card *ngFor="let campaign of campaigns"> 

    <ion-item> 
     <ion-avatar item-left> 
     <img [src]="campaign.image"> 
     </ion-avatar> 
     <h2>{{campaign.name}}</h2> 
     <p>July 5, 2016</p> 
    </ion-item> 

    <img [src]="campaign.image"> 

    <ion-card-content> 
     <p>{{campaign.description}}</p> 
    </ion-card-content> 

    <ion-row> 
     <ion-col> 
     <button primary clear small (click)="likeCampaign(campaign)" disabled= {{buttonDisabled}}> 
      <ion-icon name='thumbs-up'></ion-icon> 
      <div>{{campaign.likes.length}} Likes</div> 
     </button> 
     </ion-col> 
     <ion-col> 
     <button primary clear small (click)="shareCampaign(campaign)"> 
      <ion-icon ios="ios-share" md="md-share"></ion-icon> 
      <div>{{campaign.share.length}} Shares</div> 
     </button> 
     </ion-col> 
     <ion-col> 
     <button primary clear small (click)="optInToCampaign(campaign)"> 
      <ion-icon name='person-add'></ion-icon> 
      <div>{{campaign.wantin.length}} Opt In</div> 
     </button> 
     </ion-col> 
    </ion-row> 

    </ion-card> 

</ion-content> 

<style> 
    .social-cards ion-col { 
    padding: 0; 
    } 
</style> 

home.ts

import { Component } from '@angular/core'; 
import { NavController } from 'ionic-angular'; 
import { Toast, SocialSharing } from 'ionic-native'; 

import { CampaignProvider } from '../../providers/campaign-provider/campaign-provider'; 
import { UserProvider } from '../../providers/user-provider/user-provider'; 

@Component({ 
    templateUrl: 'build/pages/home/home.html', 
    providers: [CampaignProvider] 
}) 

export class HomePage { 
    campaignOject: {name?:string, image?:string, description?: string, likes?: number, shares?:number, wantin?:number } = {}; 
    campaigns = []; 
    like:{email?:string, campaignid?:string} ={}; 
    buttonDisabled:boolean; 
    user:{email?: string} = {}; 

    constructor(public navCtrl: NavController, private campaignProvider: CampaignProvider, private userProvider: UserProvider) { 
    this.buttonDisabled = null; 

    this.user.email = userProvider.GetLocalObject("user"); 
    this.getCampaigns(); 
    } 

    ionViewWillEnter(){ 
    console.log('Entered into the view'); 
    } 

    ionViewDidEnter(){ 
    console.log('Page was fully loaded'); 
    } 

    getCampaigns(){ 
    console.log(this.user); 

    this.campaignProvider.GetUserCampaigns(this.user).subscribe(
     data => { 
     console.log(data.result); 
     console.log(data.message); 
     this.campaigns = data.result; 
     }, 
     err => { 
     console.log(err); 
     }, 
    () => console.log('Pulling data') 
    ) 
    } 

    likeCampaign(campaign){ 
    console.log(campaign.name + ' has been liked'); 


    this.like.email = '[email protected]'; 
    this.like.campaignid = campaign._id; 
    //TODO: Pick the User Email from localstorage 
    //campaign.email = '[email protected]'; 

    console.log(this.like); 
    this.campaignProvider.LikeCampaigns(this.like).subscribe(
     data => { 
     console.log(data.result); 
     this.buttonDisabled = true; 
     Toast.show(campaign.name + " liked", "short", 'bottom').subscribe(
      toast => { 
      console.log(toast); 
      } 
     ); 

     }, 
     err => { 
     console.log(err); 
     }, 
    () => console.log(campaign.name + ' campaign was liked.') 
    ) 
    this.getCampaigns(); 
    } 

    optInToCampaign(campaign){ 
    console.log(campaign.name + ' has been opted into'); 

    this.like.email = '[email protected]'; 
    this.like.campaignid = campaign._id; 
    //TODO: Pick the User Email from localstorage 

    this.campaignProvider.WantInCampaign(this.like).subscribe(
     data => { 
     console.log(data.result); 
      Toast.show(campaign.name + " opted in to", "short", 'bottom').subscribe(
       toast => { 
       console.log(toast); 
      } 
     ); 
     }, 
     err => { 
     console.log(err); 
     }, 
    () => console.log(campaign.name + ' campaign was liked.') 
    ) 

    this.getCampaigns(); 
    } 

    shareCampaign(campaign){ 
    console.log(campaign.name + ' has been shared'); 

    this.like.email = '[email protected]'; 
    this.like.campaignid = campaign._id; 
    //TODO: Pick the User Email from localstorage 

    SocialSharing.share(campaign.description, campaign.name,campaign.image).then(() =>{ 
     console.log("Success"); 

     this.campaignProvider.ShareCampaign(campaign).subscribe(
      data => { 
      console.log(data.result); 
       Toast.show(campaign.name + " shared", "short", 'bottom').subscribe(
        toast => { 
        console.log(toast); 
       } 
      ); 
      }, 
      err => { 
      console.log(err); 
      }, 
     () => console.log(campaign.name + ' campaign was shared.') 
     ) 

    }).catch(() => { 
     console.log("Error"); 
    }); 

    this.getCampaigns(); 
    } 

} 

控制檯登錄

Angular 2 is running in the development mode. Call enableProdMode() to enable the production mode. 
Native: tried calling StatusBar.styleDefault, but Cordova is not available. Make sure to include cordova.js or run in a device/simulator 
Native: tried calling Splashscreen.hide, but Cordova is not available. Make sure to include cordova.js or run in a device/simulator 
WARNING: sanitizing HTML stripped some content (see http://g.co/ng/security#xss). 
WARNING: sanitizing HTML stripped some content (see http://g.co/ng/security#xss). 
WARNING: sanitizing HTML stripped some content (see http://g.co/ng/security#xss). 
ionViewWillEnter called 
[email protected] 
swiper initEvents attach 
Object {email: "[email protected]"} 
Username for user [object Object] 
Entered into the view 
Object {email: "[email protected]"} 
Username for user [object Object] 
Entered into the view 
Page was fully loaded 
[Object, Object, Object] 
Successfully pulled the Campaigns 
Pulling data 
Mixed Content: The page at 'https://ide.c9.io/kolexinfos/shoppa' was loaded over HTTPS, but requested an insecure image 'http://preptitude.com.ng/shoppa/shoprite.jpg'. This content should also be served over HTTPS. 
Mixed Content: The page at 'https://ide.c9.io/kolexinfos/shoppa' was loaded over HTTPS, but requested an insecure image 'http://preptitude.com.ng/shoppa/shoprite.jpg'. This content should also be served over HTTPS. 
Mixed Content: The page at 'https://ide.c9.io/kolexinfos/shoppa' was loaded over HTTPS, but requested an insecure image 'http://preptitude.com.ng/shoppa/deola.jpg'. This content should also be served over HTTPS. 
Mixed Content: The page at 'https://ide.c9.io/kolexinfos/shoppa' was loaded over HTTPS, but requested an insecure image 'http://preptitude.com.ng/shoppa/nike.jpg'. This content should also be served over HTTPS. 
[Object, Object, Object] 
Successfully pulled the Campaigns 
Pulling data 
Mixed Content: The page at 'https://ide.c9.io/kolexinfos/shoppa' was loaded over HTTPS, but requested an insecure image 'http://preptitude.com.ng/shoppa/shoprite.jpg'. This content should also be served over HTTPS. 
Mixed Content: The page at 'https://ide.c9.io/kolexinfos/shoppa' was loaded over HTTPS, but requested an insecure image 'http://preptitude.com.ng/shoppa/shoprite.jpg'. This content should also be served over HTTPS. 
Mixed Content: The page at 'https://ide.c9.io/kolexinfos/shoppa' was loaded over HTTPS, but requested an insecure image 'http://preptitude.com.ng/shoppa/deola.jpg'. This content should also be served over HTTPS. 
Mixed Content: The page at 'https://ide.c9.io/kolexinfos/shoppa' was loaded over HTTPS, but requested an insecure image 'http://preptitude.com.ng/shoppa/deola.jpg'. This content should also be served over HTTPS. 
Mixed Content: The page at 'https://ide.c9.io/kolexinfos/shoppa' was loaded over HTTPS, but requested an insecure image 'http://preptitude.com.ng/shoppa/nike.jpg'. This content should also be served over HTTPS. 
Mixed Content: The page at 'https://ide.c9.io/kolexinfos/shoppa' was loaded over HTTPS, but requested an insecure image 'http://preptitude.com.ng/shoppa/nike.jpg'. This content should also be served over HTTPS. 
+0

你可以發佈整個'home.ts'代碼嗎? – sebaferreras

+1

@sebaferreras完成檢查編輯 – kolexinfos

+0

您可以從控制檯發佈日誌嗎? –

回答

0

我會嘗試調用this.getCampaigns();ionViewDidLoad(){}內。這應該確保所有提供者在嘗試訪問它們之前都被實例化。

由於這種情況的異步性質而可能出現的另一個問題是,如果在訂閱發生之前發送值。在我以前的這種情況下,我會在ngOnInit(){}內訂閱。這一個lifecycle hook of Angular和我不完全確定什麼equivalent hook is for Ionic