我将尝试在Angular2中制作一个圆形板。例如,我想制作10个圆形,但实际上这个数字可能会改变。我想计算每个圆的半径,使其具有动态性而不是静态性。请参见以下图片示例:
以下是我的代码:
但我遇到了以下错误:
![enter image description here](https://istack.dev59.com/UTEBF.webp)
@Component({
selector:"circle"
template: `
<svg>
<circle *ngFor='#item of forLength #i=index #l=last #e=even'
cx="50%" cy="50%" [style.r]="calculateRadius()" stroke="black" stroke-width="5" fill="white"></circle>
<svg/>
`
})
export class CircleComponent{
public maxRadius:number=25;
public totalRounds:number=10;
public x:number=30;
public calculateRadius():number{
var distanceBetweenCircles=this.maxRadius/(this.totalRounds-1);
this.x-= distanceBetweenCircles;
return this.x;
}
}
但我遇到了以下错误:
calculateRadius() in CircleComponent@7:30' has changed after it was checked.
Previous value: '-7.500000000000007'.
Current value: '-36.66666666666668' in [calculateRadius() in CircleComponent@7:30]
用*ngFor
改写这个for循环有更好的方法吗?而不是写在一个单独的方法中。
calculateRadius()
函数吗?你在模板中设置SVG的r
属性吗? - Mark Rajcok