0

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

}]); 

2 Answers 2

1

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();
Sign up to request clarification or add additional context in comments.

19 Comments

Thank you for your help @Abhilash,but I getting 'asd' value as Undefined can you please make sure about that code,one more thing I am just calling 'getReportDetail' function from my html page and it will interact with my service file through 'getReportInformation()' function
@did you check your variable controllerScope? is this empty?
'$scope.report_details' only available inside service calling function
@nikhilka So now you have the access to your scope from javascript, right? But, you can't access report_details?
Exactly I need to access report_details
|
0

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.