Как я могу использовать данные Angular JS в JavaScript (Google Chart)?

0

Я хочу использовать мои угловые данные области JS внутри моей диаграммы google или JavaScript My angular 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;                   
               }
            });
        };

}]); 
Теги:
angularjs-scope
angularjs-directive
google-chartwrapper

2 ответа

1
Лучший ответ

Да, конечно. Вы можете получить доступ к своей переменной видимости контроллера вне вашей угловой.

var controllerElement = document.querySelector('[ng-controller="ReportInfoCtrl"]'); // You can use javascript or Jquery to select the controller div element.
var controllerScope = angular.element(controllerElement).scope(); // Angular provided the interface to access angular 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();
  • 0
    Спасибо за вашу помощь @ Abhilash, но я получаю значение 'asd' как неопределенное. Вы можете убедиться в этом коде, еще одна вещь, которую я просто вызываю функцию 'getReportDetail' со своей html-страницы, и она будет взаимодействовать с моим сервисным файлом через функция getReportInformation ()
  • 0
    @ Вы проверяли свою переменную controllerScope ? это пусто?
Показать ещё 18 комментариев
0

Асинхронные манипуляции с областью должны происходить в пределах $scope.apply должны быть замечены угловыми.

Ещё вопросы

Сообщество Overcoder
Наверх
Меню