javascript - 使用 PhantomJS 预渲染 AngualrJS 站点时出现 "Failed to instantiate module ngSanitize"

标签 javascript angularjs phantomjs

我正在尝试使用 PhantomJS 预呈现我的 AngularJS 网站。 (使用来自 http://www.yearofmoo.com/2012/11/angularjs-and-seo.html 的 phantomjs-runner.js)由于出现以下错误,我无法通过 PhantomJS 加载页面。在 IE/Chrome/Firefox 中不会出现此错误。

我该如何解决这个错误?

错误:

Error: [$injector:modulerr] Failed to instantiate module SpaceForAfrica due to:
Error: [$injector:modulerr] Failed to instantiate module dialogs due to:
Error: [$injector:modulerr] Failed to instantiate module ngSanitize due to:
Error: [$injector:nomod] Module 'ngSanitize' is not available! You either misspelled the module name or forgot to load it. If registering a
module ensure that you specify the dependencies as the second argument.
http://errors.angularjs.org/1.2.1/$injector/nomod?p0=ngSanitize
    at http://ajax.googleapis.com/ajax/libs/angularjs/1.2.1/angular.js:1507
    at ensure (http://ajax.googleapis.com/ajax/libs/angularjs/1.2.1/angular.js:1435)
    at module (http://ajax.googleapis.com/ajax/libs/angularjs/1.2.1/angular.js:1717)
    at http://ajax.googleapis.com/ajax/libs/angularjs/1.2.1/angular.js:3527

模块配置

var SpaceForAfrica = angular.module('SpaceForAfrica', ['ngRoute', 'HashBangURLs', 'ui.bootstrap', 'ui.bootstrap.tpls', 'google-maps', 'ui.growl', 'dialogs', 'ngSanitize', 'angularSpinner','angulartics', 'angulartics.google.analytics']).config(spaceForAfricaConfig);

最佳答案

看起来您可能缺少对 ngSanitize 代码的引用。 ngSanitize 是 AngularJS 框架 ( https://docs.angularjs.org/api/ngSanitize ) 的一部分,但是,您必须在 PhantomJS 引用之前包含一个单独的引用才能使用它。

看来您使用的是 AngularJS 1.2.1 版,因此您可以轻松地添加其中一个标签(或获取代码以包含在您自己的应用程序中。)

非缩小版:

<script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.2.1/angular-sanitize.js"></script>

缩小版:

<script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.2.1/angular-sanitize.min.js"></script>

关于javascript - 使用 PhantomJS 预渲染 AngualrJS 站点时出现 "Failed to instantiate module ngSanitize",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24092710/

相关文章:

javascript - 为什么第一页的 history.length 是 2?

javascript - 在使用 python flask-restful 和使用 AngularJS(使用 $http)时出现 CORS(跨源...)错误

javascript - 为什么 Phantom.js 不评估我的 Backbone 应用程序的工作?

javascript - 加载页面时显示带视频的模态,可选择单击按钮打开相同的模态

javascript - HTML Javascript - 防止从 dom 树的子节点执行脚本

javascript - 使用 Angular 过滤器根据导航选择过滤并显示左侧内容

java - PhantomJS 和导体框架

centos - 幻影JS 2.1.1 : "errorMessage":"Element is not currently visible and may not be manipulated

javascript - 监听 CKEditor 对话框中的点击事件

angularjs - AngularJS 中的方法重载\重写