如何在Google Apps Script中使用AngularJS

如何在Google Apps Script中使用AngularJS

IT小君   2023-05-12T00:52:05

是否可以在使用Google Apps Script的HtmlService提供的Web应用程序中使用Angular.js?

我还按照以下链接中提到的更改了Code.gs文件。
如何在使用Google Apps Script提供的HTML网站中使用Angular.js?

但是没有成功。

源代码:

Code.gs

function doGet(request) {
  return HtmlService.createTemplateFromFile('index')
      .evaluate()
      .setSandboxMode(HtmlService.SandboxMode.IFRAME);
}

function include(filename) {
  return HtmlService.createHtmlOutputFromFile(filename)
      .getContent()
}

index.html

<!DOCTYPE html>
<html ng-app="myApp">
  <head>
    <base target="_top">
  </head>
  <body ng-controller="mainCtrl">
    <h1>{{heading}}</h1>
    <p>{{message}}</p>
    <?!= include('Javascript'); ?>
     <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.4.8/angular.js"></script>
  </body>
</html>

Javascript.html

<script>
var app = angular.module('myApp',[]);
app.controller('mainCtrl',function($scope) {
  $scope.heading = 'Welcome';
  $scope.message = 'Please enjoy this helpful script';
});
</script>

我在控制台中得到的输出:

解析'sandbox'属性时出错:'allow-modals','allow-popups-to-escape-sandbox'是无效的沙盒标志。dev:14
未捕获的引用错误:angular未定义 VM4501:2
未捕获的对象

任何即时帮助都将不胜感激。

点击广告,支持我们为你提供更好的服务
评论(1)
IT小君

将angular.js的引用脚本语句移动到head部分。在引入剩余的javascript文件之前需要设置它。然后它就能正常工作了。在这里检查它: GAS-angularJS

2023-05-12T00:52:17   回复