我在组件中使用DatePipe将时间戳转换为可读表达式。但是,一旦文件被加载,我得到的例外:Angular 2 - 日期管道异常:检查后表达式已更改
例外:http://localhost:3000/app/interest/user-interest.component.html:15:15错误造成的:表达式检查后发生了变化。以前的值:'6бер。 2017' 年。当前值:'5бер。 2017' 年。
请问谁能解释一下这里发生了什么事。这是基本的代码:
用户interest.component.html
<p md-line>{{getFolderLastLearningSessionDate(folder.learningSessions)}}</p>
用户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";
}
学习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");
}