I'm having issues with my randomWidth() function calling twice, even when I remove the ng-repeat attribute from my element it still calls twice. I can't seem to figure out how to get around this issue. I'm guessing there's a way around this or maybe something obviously I'm leaving out?
HTML:
<div id="body-wrapper" ng-app="gallery" ng-controller="mainCtrl">
<section id="sidebar">
<h1>Gallery</h1>
</section>
<main>
<div class="box" ng-repeat="img in imgs" ng-style="{'width': randomWidth()}">
<div class="box-wrapper"></div>
</div>
</main>
</div>
Javascript:
angular.module('gallery', [])
.controller('mainCtrl', function($scope){
$scope.imgs = [
{
title: 'image1'
},
{
title: 'image2'
},
{
title: 'image3'
},
{
title: 'image4'
},
{
title: 'image5'
},
{
title: 'image6'
}
];
$scope.randomWidth = function(){
const widths = ['25%', '33%', '40%', '50%'];
const max = widths.length;
const min = 0;
var r = Math.floor(Math.random() * (max - min)) + min;
console.log(widths[r]);
return widths[r];
}
})