NIKHIL K A
NIKHIL K A

Reputation: 328

How can I use Angular JS data inside JavaScript(Google Chart)?

I want to use my angular JS scope data inside my google chart or JavaScript My angular JS file given below

angular.module('reports').controller('ReportInfoCtrl', ['$scope', 'reports', '$rootScope','$location','blockUI',
    function ($scope, reports, $rootScope, $location, blockUI) {
        $scope.getReportDetail = function () {
            blockUI.start();
            reports.getReportInformation().then(function (data) {
                blockUI.stop();
                if (data !== undefined) {
                    $scope.report_details = data;                   
               }
            });
        };

}]); 

Upvotes: 0

Views: 273

Answers (2)

meriton
meriton

Reputation: 70584

Asynchronous scope manipulations must occur within a $scope.apply to be noticed by angular.

Upvotes: 0

Abhilash Augustine
Abhilash Augustine

Reputation: 4208

Yes, sure. You can access your scope variable of controller out side your angular.

var controllerElement = document.querySelector('[ng-controller="ReportInfoCtrl"]'); // You can use javascript or Jquery to select the controller's div element.
var controllerScope = angular.element(controllerElement).scope(); // Angular provided the interface to access angular's scope
var asd = controllerScope.report_details; // Now you can access all scope variable using 'controllerScope'

Update

angular.module('reports').controller('ReportInfoCtrl', ['$scope', 'reports', '$rootScope','$location','blockUI',
    function ($scope, reports, $rootScope, $location, blockUI) {
        $scope.getReportDetail = function () {
            blockUI.start();
            reports.getReportInformation().then(function (data) {
                blockUI.stop();
                if (data !== undefined) {
                    $scope.report_details = data;                
                }
                return data;   
            });
        };
}]); 

And in your js file,

var asd = controllerScope.getReportDetail();

Upvotes: 1

Related Questions