In one of my components, I have the following method:
public *numGen(): Iterator<number> {
for (let i = 0; i < 5; ++i)
yield i;
}
Additionally, my HTML contains this snippet:
<p *ngFor="let n of numGen()">{{n}}</p>
I anticipated that this would display the numbers 0 to 4 in separate paragraphs as follows:
<p>0</p>
<p>1</p>
<p>2</p>
<p>3</p>
<p>4</p>
However, while it does produce the expected output, it also triggers an error message:
ExpressionChangedAfterItHasBeenCheckedError: Expression has changed after it was checked.
Previous value: 'ngForOf: [object Generator]'. Current value: 'ngForOf: [object Generator]'.
Does anyone have a solution to prevent this error from occurring?