2016-02-25 18 views
2

是否可以将Angular.js作为在Google Apps脚本中使用HtmlService服务的Web应用程序的一部分?如何在Google Apps脚本中使用AngularJS

我还更改了Code.gs文件,如下面链接所述。
How can I use Angular.js in a Google Apps Script served HTML site?

但没有成功。

源代码:

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> 

输出我得到控制台:

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

任何直接的帮助将是非常可观的。

回答

4

将angular.js include脚本语句移动到头部部分。它需要在包含剩余的JavaScript文件之前进行设置。它的作品。检查它在这里: GAS-angularJS

+0

Thanks..its working :) –