我在尝试这样做时遇到此异常 - messages.component.html:
#ifndef ARLINK_H
#define ARLINK_H
#include <iostream>
#include <cstdlib>
#include "Link.h"
using namespace linkedlist;
class bag{
typedef size_t size_type;
typedef node::value_type value_type;
private:
node *head_ptr; //list head pointer
size_type m_nodes; //number of nodes in the list
public:
// CONSTRUCTORS and DESTRUCTOR
bag( );
bag(const bag& source){
node *tail_ptr; // Needed for argument to list_copy
list_copy(source.head_ptr, head_ptr, tail_ptr); //Giving Error Link List definition not resolved
m_nodes = source.m_nodes;
}
needToPrint函数 - messagess.component.ts:
<div *ngFor = "let message of messages | async">
<div *ngIf = "needToPrint(message.timestamp | date: 'dd/MM/yy')">
<p class = "date-stamp"> {{ message.timestamp | date: "MM/dd/yy" }} </p>
</div>
.
.
</div>
我知道此异常仅在开发模式下出现,但我该如何解决? (我试着读一下这个,但仍然没有成功修复它。)
感谢。
答案 0 :(得分:1)
未经测试,但希望这会有所帮助。
如上所述,错误是由模板中的函数调用引起的,即
needToPrint(message.timestamp | date: 'dd/MM/yy')
我强烈建议你重构你的代码,因为你没有从模板中调用函数,因为更改检测原因被认为是不好的做法,更糟糕的是它会导致无限循环:*ngFor running an infinite loop in angular2
此解决方法可能是使用ChangeDetectorRef
手动调用更改检测。导入它,注入构造函数并在needToPrint
- 函数:
import { ChangeDetectorRef } from '@angular/core';
constructor(private ref: ChangeDetectorRef) { }
needToPrint(date) {
if (this.savedDate != date){
this.savedDate = date;
this.ref.detectChanges();
return true;
}
this.ref.detectChanges();
return false;
}