2017-03-14 8 views
0

초급자입니다. ionic2Ng For 루프가 제대로 작동하지 않습니다.

실제로 Push 알림을 위해 FCM 플러그인을 사용하고 있습니다.

이 내 응용 프로그램 component.ts

 FCMPlugin.onNotification(function(d){ 
      if(d.wasTapped){ 
      console.log(d); 
      var nav=self.appCtrl.getActiveNav().setRoot(NotificationsPage); 
     }) 

입니다 그것은 내가 알림 페이지가 각각의 페이지 (알림 페이지)로 리디렉션 클릭도 WRK의 좋아 그래서입니다.

나는 firebase 콜렉션에서 데이터를 가져 와서 array에 할당했습니다.

배열 변수 이름은 알림입니다. 배열 값을 닫았습니다. 정상적으로 작동합니다.

virtualScroll을 사용하여 UI에 배열 표시. 내 HTML 코드를 제공합니다 아래

는 내 알림 페이지의 구성 요소 (TS 파일) 아래의 통지를 각각의 페이지 (알림 페이지)

<ion-card class="card" [virtualScroll]="Notifications"> 
     <ion-item (click)="navigate(Notifications.value.TYPE,Notifications.value.FROM,Notifications.value.$key,Notifications.value.TO,Notifications.value.MSG,Notifications.value.STATUS,Notifications.time)" *virtualItem="let Notification"> 
     <ion-avatar item-left> 
      <img *ngIf="!Notification.userval.FILE" src="https://firebasestorage.googleapis.com/v0/b/apartments-ea9e5.appspot.com/o/default.png?alt=media&token=a64af538-17a7-46e1-9e38-383c1df060cf"> 
      <img *ngIf="Notification.userval.FILE" [src]="Notifications.userval.FILE"> 
     </ion-avatar> 
     <p>{{Notification.value.MSG}}</p> 
     <p>{{Notification.time}}</p> 
     <p style="text-align:right;color:#334bfa;">{{Notifications.value.TYPE}}</p> 
     </ion-item> 
    </ion-card> 

을 밀어입니다.

  this.authservice.getalluser().first().subscribe(namelist=> 
       { 
       var users=[]; 
       namelist.forEach(userval=> 
       { 
        users.push(userval.val()); 
       }) 

       for(var i in val) 
       { 
       this.Time=val[i].SEND_TIME; 
       var timeagoIns = timeago(); 
       var result=timeagoIns.format(this.Time); 
       console.log(result); 
       var user=users.filter(users=>users.USER_ID.toString() === val[i].FROM.toString()); 
       this.Notifications.push({ 
        value:val[i], 
        time:result, 
        userval:user[0] 
        }) 
       Console.log(this.Notifications); 
      }) 

배열 값은 UI를 업데이트하지 않지만 알림 값은 처리하지 않습니다. 정상적으로 작동합니다.

왜 UI가 배열 값으로 업데이트되지 않습니다.

이 문제를 해결하는 방법.

친절한 조언,

감사합니다.

답변

0

배열을 이와 같이 업데이트합니까?

push.on('notification', (data) => { 
    // update array 
}); 

당신은 방법 다음 UI 업데이트 안 배열을 업데이트하는 경우. 배열이 이제 ngZone을 벗어 났기 때문입니다. UR reply.I 배열 value.I를 업데이트해야 각각의 page.How에게 알림 리디렉션을 클릭 file.When 응용 프로그램 구성 요소에 배열 값을 업데이트 할 경우이 경우 당신은 어떤 pushnotifications 값을 전달,

push.on('notification', (data) => { 
    this.ngZone.run(() => { 
     // update array 
    }); 
}); 
+0

덕분에이를 doesnot 사용할 수 있습니다 array.Actually 각 페이지에 firebase 컬렉션에서 데이터를 수집. 왜 배열 값을 업데이 트됩니다. –

+0

질문을 편집하고 배열 업데이트 코드를 추가 하시겠습니까? 그렇지 않으면 많은 것을 가정하여 대답하기가 매우 어렵습니다. – Math10

+0

Kindly Pls Check It.I 코드를 업데이트하십시오. –

관련 문제