0
我使用離子2.這裏開發聊天應用是我的html代碼伍與通話功能
<ion-content padding>
<div *ngIf="online === true">
<ion-refresher (ionRefresh)="onPullOldMessages($event)">
<ion-refresher-content></ion-refresher-content>
</ion-refresher>
<div class="chat" *ngIf="chatval">
<div class="messagesholder"
*ngFor="let chat of chatval | orderby:'[date]'; let i = index;let first=first;let last = last;">
<div *ngIf="chat.sender == currentuser || chat.receiver == currentuser" >
<p class="chat-date" id="abc" #abc>{{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>
</div>
</div>
</ion-content>
它工作正常。顯示聊天信息。但我需要不顯示相同的日期值,因爲我叫checkdate(chat.date)
。
這裏是我的功能
checkdate(date)
{
var res = date.split(" ");
var A=res[0];
var local=localStorage.getItem('chatdate');
this.msgdate="";
if(local === undefined || local === null)
{
this.msgdate=A;
localStorage.setItem('chatdate',this.msgdate);
}
else if(local !== undefined)
{
console.log(local != A);
if(local != A)
{
this.msgdate = A;
localStorage.setItem('chatdate',this.msgdate);
}
}
console.log("date value");
}
其實數組的長度是3。但是這個函數調用許多時間。我檢查了這個函數調用了多少次。因爲我只是安慰了字符串值。它安慰了很多次,像100次。
如何停止反覆調用功能?
Thanks.I分配變量只更新最後一項值的數組。 – ANISUNDAR
我需要不顯示重複value.can你幫我... – ANISUNDAR
對不起,我不明白你的意思:)你能顯示代碼,而不是你已經嘗試過嗎? – Alex