【发布时间】:2017-07-28 01:16:16
【问题描述】:
我在组件中使用 DatePipe 将时间戳转换为可读表达式。但是一旦加载了文档,我就会得到异常:
异常:http://localhost:3000/app/interest/user-interest.component.html:15:15 中的错误由以下原因引起:表达式在检查后已更改。以前的值:'6 бер。 2017 年'。当前值:'5 бер。 2017 年。
任何人都可以,请解释一下这里发生了什么。这是基本代码:
用户兴趣.component.html
<p md-line>{{getFolderLastLearningSessionDate(folder.learningSessions)}}</p>
user-interest.component.ts
getFolderLastLearningSessionDate(sessions:Array<LearningSession>):string {
if (sessions)
try {
return this.learningSessionService.getLearningSessionDate(this.learningSessionService.getLastLearningSession(sessions));
} catch (ex) {
console.log(ex);
}
else return "Folder have not bean studied yet";
}
learning-sessions.service.ts
public getLearningSessionDate(session:LearningSession):string {
let datePipe = new DatePipe("uk-UA");
return datePipe.transform(session.sessionDate);
}
public getLastLearningSession(sessions:Array<LearningSession>):LearningSession {
if (sessions) {
return sessions.sort(
(session1:LearningSession, session2:LearningSession) => {
return session2.sessionDate.getDate() - session1.sessionDate.getDate();
}).shift();
}
else
throw new Error("folder is not studied yet");
}
【问题讨论】:
标签: angular angular2-pipe