如何在JavaScript(谷歌图表)中使用Angular JS数据

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

本文关键字:Angular 数据 JS JavaScript 谷歌      更新时间:2023-09-26

我想在谷歌图表或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;                   
               }
            });
        };
}]); 

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

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

异步作用域操作必须发生在$scope.apply内才能被angular注意到。