簡體   English   中英

從Google腳本中獲取數據時,Angular變量未在頁面上刷新

[英]Angular variable are not refreshing on page when fetching data from google script

做一個Google Script APP。 使用服務器端方法返回字符串數組。 getClassRoomList()

您能否建議我當前的HTML有什么問題? 由於成功處理程序在響應時運行良好。 但是ng變量消息沒有反映在頁面上; 而jQuery確實填充了表格。

        <!DOCTYPE html>
        <html ng-app="myApp">
            <head>
                <base target="_top">
                <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
                <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.4.8/angular.js"></script>
                <script>
                    var app = angular.module('myApp',[]);
                    app.controller('mainCtrl',function($scope){
                    $scope.message = [];
                    $scope.populateTable = function(array){
                        //Setting ng variable; but the page doesn't show anything
                        $scope.message = array;

                        //Setting the Table by JQuery; it does work.
                        var table = $('#myTable');
                        table.empty();
                        for (var i = 0; i < array.length; i++) {
                            var item = '<tr><td><div class="classname">' + array[i] +'</div></td></tr>';
                            table.append(item);
                        }
                    };
                    $scope.mainClick = function(){
                        $scope.message = $scope.message + 'chirag';
                        google.script.run.withSuccessHandler($scope.populateTable).getClassRoomList();
                    };
                    });
                </script>
            </head>
            <body ng-controller="mainCtrl">
                <button ng-click="mainClick()">Proceed</button>
                <table id="myTable"></table>
                <div ng-bind="message"></div>
            </body>
        </html>

這可行。 謝謝。 google.script.run.withSuccessHandler((e) => {$scope.populateTable(e); $scope.$apply();}).getClassRoomList();

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM