简体   繁体   English

使用PhantomJS预渲染AngualrJS网站时“无法实例化模块ngSanitize”

[英]“Failed to instantiate module ngSanitize” when pre-rendering AngualrJS site with PhantomJS

I'm attempting to pre-render my AngularJS site using PhantomJS. 我正在尝试使用PhantomJS预渲染我的AngularJS网站。 (With phantomjs-runner.js from http://www.yearofmoo.com/2012/11/angularjs-and-seo.html ) I'm unable to load the page through PhantomJS as the error below occurs. (使用来自http://www.yearofmoo.com/2012/11/angularjs-and-seo.html的 phantomjs-runner.js)我无法通过PhantomJS加载页面,因为下面的错误发生了。 This error does not occur in IE/Chrome/Firefox. 在IE / Chrome / Firefox中不会发生此错误。

How do I go about fixing this error? 我该如何解决此错误?

Error: 错误:

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

Module config 模块配置

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);

It looks like you might be missing a reference to the ngSanitize code. 看起来您可能缺少对ngSanitize代码的引用。 ngSanitize is part of the AngularJS framework ( https://docs.angularjs.org/api/ngSanitize ), however, you have to include a separate reference before your PhantomJS reference in order to utilize it. ngSanitize是AngularJS框架( https://docs.angularjs.org/api/ngSanitize )的一部分,但是,您必须在PhantomJS参考之前包含一个单独的引用才能使用它。

It appears you are using version 1.2.1 of AngularJS, so you could easily just add one of these tags (or grab the code to include in your own app.) 您似乎正在使用AngularJS的1.2.1版本,因此您可以轻松添加其中一个标记(或者获取代码以包含在您自己的应用中)。

Non-minified: 非精缩:

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

Minified: 精缩:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM