首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Ionic 2聊天页面相同的值重复

Ionic 2聊天页面相同的值重复
EN

Stack Overflow用户
提问于 2017-04-12 13:33:35
回答 1查看 57关注 0票数 0

我正在使用ionic 2

下面是我的模板代码

代码语言:javascript
复制
 <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>

下面是我的函数

代码语言:javascript
复制
checkdate(i)
  {
    console.log("date");
    console.log(i);
    this.msgdate=i;
  }

我需要相同的日期值不是检查日期我使用此函数{{ repeated.Because (chat.date)}}获取输入元素值。

但是我得到了这个错误。

代码语言:javascript
复制
Error in ./ChatPage class ChatPage - caused by: Expression has changed after it was checked. Previous value: 'true'. Current value: 'false'.

我怎样才能解决这个问题...

敬请指教,

谢谢

EN

回答 1

Stack Overflow用户

发布于 2017-04-12 13:46:41

由于您试图修改在loop语句中执行后端处理的对象,因此出现以下错误。

代码语言:javascript
复制
Error in ./ChatPage class ChatPage - caused by: Expression has changed after it was checked. Previous value: 'true'. Current value: 'false'.

如果你想获得唯一的日期,那么你可以像下面的例子一样,它将从你的集合中给出唯一的chatDate:

代码语言:javascript
复制
let Values = this.chatval.map(function (item) { return item["date"]; }).filter(this.OnlyUnique);

OnlyUnique(value, index, self): any {
    return self.indexOf(value) === index;
}
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/43361035

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档