简体   繁体   中英

function doesn't return variable

this really easy and stupid question but I'm already stuck on 2 two days. I have to receive data from server or whatever and I wrote easy function, so this guy

$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;
};

and this guy

<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> 

return for me digit 5 and pushing it into my range

if I use this guy

$scope.myTar = function(target) {
    $log.debug('['+target+']')
};

it returns me on console all my necessary values but if I use this guy

$scope.myTar = function(target) {
    return target;
};

and

<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> 

it returns me in console target is undefined, what's wrong?

the gaugeData is coming from other function LoadGaugesData I tried to input this part of code to myTar function but it still shows me same thing. Also as you can see my range is using gaugeData.target and it works fine... this is part of it

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);
}}

for stupid question, stupid answer

I inserted max in my push function inside range like this

$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(**max**);
    return input;
};

thanks, for advice to check every step in debugger

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM