如何谷歌Apps脚本中使用AngularJS脚本、Apps、AngularJS

2023-09-13 03:45:51 作者:睾处不胜寒

时有可能使用Angular.js作为一个web应用程序的一部分,在谷歌Apps脚本使用HtmlService服?

Is it possible to use Angular.js as part of a web app served using HtmlService in Google Apps Script?

我也改变了 code.gs 下面链接中提到的文件。结果How我可以使用Angular.js在谷歌Apps脚本提供HTML的网站?

但没有得到成功。

来源$ C ​​$ C:

code.gs

Code.gs

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

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

index.html的

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

Javascript.html

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

输出我得到控制台:

错误在解析沙盒属性:让-情态动词,  让 - 弹出窗口对逃逸的沙箱'是无效的沙箱标志。开发:14结果  未捕获的Ref​​erenceError:角没有定义VM4501:2结果未捕获  对象

Error while parsing the 'sandbox' attribute: 'allow-modals', 'allow-popups-to-escape-sandbox' are invalid sandbox flags. dev:14 Uncaught ReferenceError: angular is not defined VM4501:2 Uncaught object

任何直接的帮助将是非常美联社preciable。

Any immediate help will be highly appreciable.

推荐答案

移动angular.js包括脚本语句转换成头部分。它需要包括剩余的javascript文件之前进行设置。它的工作原理呢。点击此处查看: GAS-angularJS

Move the angular.js include script statement into the head section. It needs to be setup before the remaining javascript file is included. It works then. check it here: GAS-angularJS