1

I'm working on angularjs google column chart. My requirement is to assign the value from one javascript function to the other variable defined in other javascript function.

example code snippet for myController.js

   var globalID;
   app.controller('myChart',['$rootScope','$scope','$uibModal','myService',function($rootScope,$scope,$uibModal,myService)  {
    $scope.chart = {};
    $scope.chart.options = {
        "title": "Summary API Tests",
        'fontSize': '12',
        "isStacked": "true",
        colors: ['blue', 'cyan', 'red'],
        axisFontSize : 8,
    };
    $scope.chart.type = "ColumnChart";
    $scope.function2= function( event ) {
         alert('in function2');
         /* want to assign the value of val from below lines to globalID */
         /* globalID = val; */
    };
    /* I want to invoke below lines in $scope.chartClick*/
    $scope.function1= function (selectedItem) {
            $scope.chart.data.rows[selectedItem.row].c[0].v;
            val = $scope.chart.data.rows[selectedItem.row].c[0].v;

            alert("inside function1: " + val);
        };

        //some more logic below


        });

In the above js file, i want to assign the value of val from $scope.function1 to globalID inside function2.

1 Answer 1

1

Set the value in the scope

$scope.selected = function (selectedItem) {
    $scope.chart.data.rows[selectedItem.row].c[0].v;
    $scope.selectedBarId = $scope.chart.data.rows[selectedItem.row].c[0].v;
    alert("Selected bar : " + $scope.selectedBarId);
};

$scope.chartClick = function( event ) {
     alert('in chartClick');
     if($scope.selectedBarId){
         // your business if a bar is selected
     }
};
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.