I am attempting to create a circular arrangement of links using Angular 2. I have a function that sets the fixed location of the style.left
and style.top
for each link, based on the number of links in the circle. I've attempted to use this code in the constructor of my component, but Angular fails to build, giving me an error that the items.length
property is null.
Here's my component class code which is a mix of typescript and javascript:
export class PlayersComponent {
items: any;
constructor() {
this.items = document.querySelector('.circle');
for(var i = 0, l = this.items.length; i < l; i++){
this.items[i].style.left = (50 - 35*Math.cos(-0.5 * Math.PI - 2*(1/l)*i*Math.PI)).toFixed(4) + "%";
this.items[i].style.top = (50 + 35*Math.sin(-0.5 * Math.PI - 2*(1/l)*i*Math.PI)).toFixed(4) + "%";
}
}