Angular Directive не будет работать вообще в IE

0

Это мой первый набег на angularjs, я успешно создал веб-приложение с использованием графиков Google и углов, которое работает в Firefox и в Chrome. Я надеялся закончить этот проект сегодня, я не тестировал его в IE, поскольку я пошел, и вот он полностью сломан в IE.

Ссылка, которую я использовал, чтобы помочь мне с угловой стороны вещей, - это эта;

http://jrrera.github.io/angularjs/2014/04/05/a-better-way-to-integrate-angularjs-and-google-charts/

Когда я пробовал код в IE, элемент DOM, куда должен идти график, вообще не заполняется, мой вывод состоит в том, что директива не активируется. Здесь есть два ключевых кода:

директива;

app.directive("googleChart",function(){  
    return{
        restrict : "A",
        link: function($scope, $elem, $attr){
            var model;

            // Function to run when the trigger is activated
            var initChart = function() {

                // Run $eval on the $scope model passed 
                // as an HTML attribute
                model = $scope.$eval($attr.ngModel);

                // If the model is defined on the scope,
                // grab the dataTable that was set up
                // during the Google Loader callback
                // function, and draw the chart
                if (model) {
                    var dt = model.dataTable,
                        options = {},
                        chartType = $attr.googleChart;

                    if (model.title) {
                        options.title = model.title;
                    }

                    var googleChart = new google.visualization[chartType]($elem[0]);
                    googleChart.draw(dt,options)
                }
            };

            // Watch the scope value placed on the trigger attribute
            // if it ever flips to true, activate the chart
            $scope.$watch($attr.trigger, function(val){
                if (val === true) {
                    initChart(); 
                }
            });

        }
    }
});

и div, который будет заселен в index.htm;

  <div google-chart="ColumnChart" ng-model="dataModel.visual" trigger="activateChart"></div>

Хотя моя версия этого кода из приведенной выше ссылки более продвинута, в ней ядро использует этот точный метод создания экземпляра. Это происходит во всех версиях Internet Explorer, включая Edge и 11. Будучи относительно новым учеником AngularJs, очевидно, что я в темноте, что делать дальше. Может ли кто-нибудь предложить мне совет? Большое спасибо.

  • 0
    какие-либо ошибки в консоли?
  • 0
    Какова реальная проблема, которую вы видите?
Показать ещё 3 комментария
Теги:
dom
internet-explorer
google-visualization

1 ответ

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

уточнить

var loadGoogle = ChartService.loadGoogleVisualization();

    // If the Google Loader request was made with no errors, 
    // register a callback, and construct the chart data
    // model within the callback function
    if (loadGoogle) {

        google.setOnLoadCallback(function() {

            $scope.dataModel.visual.dataTable = new google.visualization.DataTable();

            // Set up the dataTable and columns
            var dataTable = $scope.dataModel.visual.dataTable;
            dataTable.addColumn("string","Date")
            dataTable.addColumn("number","Minutes")

            // Populate row data
            dataTable.addRow(["3/1/14",5]);
            dataTable.addRow(["3/2/14",13]);

            // Update the model to activate the chart on the DOM
            // Note the use of $scope.$apply since we're in the 
            // Google Loader callback.
            $scope.$apply(function(){
                $scope.activateChart = true;    
            });
        });  
    }

стали;

google.load("visualization", "1", {packages:["corechart"], callback: drawChart});       


    $scope.dataModel.visual.dataTable = new google.visualization.DataTable();
    // Set up the dataTable and columns
    var dataTable = $scope.dataModel.visual.dataTable;
    dataTable.addColumn("string","Date")
    dataTable.addColumn("number","Minutes")

    // Populate row data
    dataTable.addRow(["3/1/14",5]);
    dataTable.addRow(["3/2/14",13]);

    // Update the model to activate the chart on the DOM
    // Note the use of $scope.$apply since we're in the 
    // Google Loader callback.
    $scope.$apply(function(){
        $scope.activateChart = true;    
    });

Ещё вопросы

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