2017-04-12 39 views
0

我使用的離子2離子2聊天頁面相同的值被重複

這裏是我的模板代碼

<div class="messagesholder" *ngFor="let chat of chatval | orderby:'[date]'; let last = last"> 
      {{last ? callFunction() : ''}} 

     <div *ngIf="chat.sender == currentuser || chat.receiver == currentuser"> 
        <p *ngIf="msgdate === undefined" class="chat-date" #ChatDate id="ChatDate" >{{chat.date | amDateFormat:'LL'}}</p> 
        {{checkdate(chat.date)}} 
     </div> 

     <div class="message" *ngIf="chat.sender == currentuser || chat.receiver == currentuser" [ngClass]="{'me': currentuser == chat.sender}"> 
       <div class='image' *ngIf="chat.path" > 
        <img *ngIf="chat.path" [src]="chat.path" imageViewer/><br> 
        <span *ngIf="chat.path_text">{{chat.path_text}}</span> 
        <span style="font-size:9px;">{{chat.date | amDateFormat:'hh:mmA'}}</span> 
       </div> 
       <div *ngIf="chat.message_text"> 
       <span>{{chat.message_text}}</span> 
       <span style="font-size:9px;">{{chat.date | amDateFormat:'hh:mmA'}}</span> 
       </div> 
      </div> 
    </div> 

這裏是我的功能

​​

我需要相同的日期值都不要重複。因爲我使用此函數{{checkdate(chat.date)}}得到輸入元素值。

但我越來越這個錯誤。

Error in ./ChatPage class ChatPage - caused by: Expression has changed after it was checked. Previous value: 'true'. Current value: 'false'. 

我怎樣才能解決這個問題?

請諮詢我,

感謝

回答

0

你得到以下錯誤,因爲你正在試圖修改的執行對象後端循環語句中的進程。

Error in ./ChatPage class ChatPage - caused by: Expression has changed after it was checked. Previous value: 'true'. Current value: 'false'. 

如果你想要獲得獨特的日期,那麼你可以嘗試如下例所示,它會給您從您的收藏獨特chatDate:

let Values = this.chatval.map(function (item) { return item["date"]; }).filter(this.OnlyUnique); 

OnlyUnique(value, index, self): any { 
    return self.indexOf(value) === index; 
} 
+0

Thanks.I有一個doubt.I使用此功能如何我可以在ng中顯示唯一的日期值嗎 – ANISUNDAR

+0

可以幫我嗎 – ANISUNDAR

+0

你可以在for語句中使用「Values」變量,例如* ngFor =「let item of Values」 –