2016-10-21 3 views
1

서비스에서 데이터를 가져와 즉시 응답하지 않는 Ionic 2 페이지를 찾으십시오. 브라우저에서도 장치, 시뮬레이터 모두에서 아무 것도 클릭 할 수 없습니다.이오니아 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 done 점검 편집 – kolexinfos

+0

콘솔에서 로그를 게시 할 수 있습니까? –

답변

0

나는 ionViewDidLoad(){} 내부 this.getCampaigns();를 호출하려고 할 것입니다. 이것에 의해, 액세스하려고하기 전에 모든 프로 바이더를 인스턴스화 할 수있을 필요가 있습니다.

이러한 시나리오의 비동기 특성으로 인해 발생할 수있는 또 다른 문제는 전에 구독이 이루어지기 전에 방출되는 것입니다. 이전에 이런 광산의 일부 시나리오에서는 ngOnInit(){}을 구독했습니다. 이 lifecycle hook of Angular과 나는 정확히 무엇이 equivalent hook is for Ionic을 모르겠다.