0

I want to use var variable in scope. How can I do like this: $scope.jsondata.var

In this example I want to use datePeriod variable in $scope.myData[index].daily so $scope.myData[index].datePeriod in controller.

Note: daily is a json data element. It's changes daily, weekly, monthly.

var datePeriod = $scope.datePeriod;

$http.get("reports?type="+datePeriod).then(function(response) {
    $scope.myData = response.data;
    angular.forEach($scope.myData, function(value, index) {
        dailyData.push({
            y: $scope.myData[index].daily,
            a: $scope.myData[index].TOTAL_CIRO,
            b: $scope.myData[index].DELIVERY_TOTAL
        });
        console.log(datePeriod);
    });
georgeawg
  • 48,608
  • 13
  • 72
  • 95
  • oops! without quotes `$scope.myData[index][datePeriod]` where `datePeriod = daily, weekly, monthly` – skdonthi Mar 13 '19 at 17:50

1 Answers1

1

You can use like this $scope.myData[index][datePeriod]

where datePeriod = daily or weekly or monthly

skdonthi
  • 1,308
  • 1
  • 18
  • 31