I have a seemingly simple question that has been stumping me for the past two days. I need to retrieve data from a server and wrote a basic function to do so. However, I am facing an issue with it.
$scope.myTar = function() {
return 5;
};
$scope.identity = angular.identity;
$scope.range = function(min, max, step){
step = Math.floor((max+5)/3);
var input = [];
for (var i = min; i < max+5; i += step)
input.push(i);
input.push($scope.myTar());
return input;
};
When implementing the following code:
<div ng-repeat="n in range(0, gauge.gaugeData.target) |orderBy:identity">
<div ng-class="{ 'numberGaugeBar-goal': n == myTar() }"></div>
<div class="numberGaugeNumbers-hashHolder"></div>
<div class="numberGaugeNumbers-numberHolder"> {{n}} </div>
</div>
It successfully returns the digit 5 and adds it to my range.
However, when using the updated code below:
$scope.myTar = function(target) {
$log.debug('['+target+']')
};
The console displays all the necessary values. But if I use this version:
$scope.myTar = function(target) {
return target;
};
And implement the following:
<div ng-repeat="n in range(0, gauge.gaugeData.target)|orderBy:identity">
<div ng-class="{ 'numberGaugeBar-goal': n == myTar(gauge.gaugeData.target) }"></div>
<div class="numberGaugeNumbers-hashHolder"></div>
<div class="numberGaugeNumbers-numberHolder"> {{n}} </div>
</div>
I encounter an error where the console states that "target is undefined." What could be causing this issue?
The gaugeData is obtained from another function called LoadGaugesData. Despite attempting to integrate this code into myTar function, the problem persists. It's worth noting that my range function utilizes gaugeData.target without any problems...
for (var idx in $scope.sectionDescriptives.scoreSections) {
section = $scope.sectionDescriptives.scoreSections[idx];
for (var gaugeIdx in section.gauges) {
var gauge = section.gauges[gaugeIdx];
var gaugeData = $scope.getGaugeData(gauge.id);
gauge.gaugeData = gaugeData;
gauge.target = gaugeData.target;
section.gauges[gaugeIdx].gaugeData = $scope.getGaugeData(gauge.id);
}}