如何在JavaScript(Google Chart)中使用Angular JS数据?

时间:2015-11-26 05:53:52

标签: javascript angularjs angularjs-directive angularjs-scope google-chartwrapper

我想在谷歌图表或JavaScript中使用我的角度JS范围数据 我在下面给出的角度JS文件

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 个答案:

答案 0 :(得分:1)

是的,当然。您可以在角度范围内访问控制器的范围变量。

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'

<强>更新

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

在你的js文件中,

var asd = controllerScope.getReportDetail();

答案 1 :(得分:0)

异步范围操作必须在$scope.apply范围内进行,以便通过angular注意到。