Angularjs的PhantomJS快照(Argument'MainCtrl'不是函数,未定义)

时间:2017-01-04 02:44:34

标签: angularjs phantomjs snapshot

应用程序通过本地服务和远程服务器正常工作。当通过phantomjs处理快照时,我得到错误“Argument'MainCtrl'不是函数,未定义”

我使用来自yearofmoo的这个git repo的make-snapshot.sh和.phantomjs-runner.js:https://github.com/yearofmoo-articles/AngularJS-SEO-Article

我的索引文件:

<!doctype html>
<html class="no-js" data-ng-app="showhaus">
<head>
  <meta charset="utf-8">
  <title>showhaus: new york show listings and venues </title>
    <meta name="description" content="showhaus is an open directory of live music and venues across a variety of cities.">
  <meta name="keywords" content="concerts, music, shows, venues, diy, indie">
    <meta name="viewport" content="initial-scale=1, maximum-scale=1">
  <link rel="icon"
        type="image/png"
        href="/favicon.ico">
  <!-- Place favicon.ico and apple-touch-icon.png in the root directory -->
  <!-- build:css({.tmp,app}) styles/main.css -->
    <!-- bower:css -->
    <!-- endbower -->
  <link rel="stylesheet" href="_css/main.css">
  <link rel="stylesheet" href="_css/jqtheme/jquery-ui.min.css">
  <link rel="stylesheet" href="_css/font-awesome.min.css">
  <link rel="stylesheet" href="_css/colorbox.css">
  <!-- endbuild -->
  <!--install karla via google fonts -->
  <link href='https://fonts.googleapis.com/css?family=Karla:400,700,400italic,700italic' rel='stylesheet' type='text/css'>
</head>
<body data-status="" ng-controller="indexCtrl">
<!--[if lt IE 7]>
<p class="browsehappy">You are using an <strong>outdated</strong> browser. Please <a href="http://browsehappy.com/">upgrade your browser</a> to improve your experience.</p>
<![endif]-->

<!-- Add your site or application content here -->
<div class="container">

  <div data-ng-view></div>

</div>

<!--[if lt IE 9]>
<script src="bower_components/es5-shim/es5-shim.js"></script>
<script src="bower_components/json3/lib/json3.min.js"></script>
<![endif]-->
<!-- build:js(app/..) scripts/vendor.js -->
<!-- bower:js -->
<script src="bower_components/jquery/dist/jquery.js"></script>
<script src="bower_components/angular/angular.js"></script>
<script src="bower_components/json3/lib/json3.js"></script>
<script src="bower_components/angular-resource/angular-resource.js"></script>
<script src="bower_components/angular-cookies/angular-cookies.js"></script>
<script src="bower_components/angular-sanitize/angular-sanitize.js"></script>
<script src="bower_components/angular-animate/angular-animate.js"></script>
<script src="bower_components/angular-touch/angular-touch.js"></script>
<script src="bower_components/angular-route/angular-route.js"></script>
<script src="bower_components/jquery-ui/jquery-ui.js"></script>
<script src="bower_components/ckeditor/ckeditor.js"></script>
<script src="bower_components/jquery-colorbox/jquery.colorbox.js"></script>
<script src="bower_components/angularUtils-pagination/dirPagination.js"></script>
<!-- endbower -->
<!-- endbuild -->
<script src="https://maps.googleapis.com/maps/api/js?sensor=false"></script>
<script src="scripts/jquery.timepicker.min.js"></script>
<!-- build:js({.tmp,app}) scripts/scripts.js -->
<script src="scripts/app.js"></script>
<script src="scripts/controllers/indexCtrl.js"></script>
<script src="scripts/controllers/main.js"></script>
<script src="scripts/controllers/about.js"></script>
<script src="scripts/controllers/post.js"></script>
<script src="scripts/controllers/edit.js"></script>
<script src="scripts/controllers/showpage.js"></script>
<script src="scripts/controllers/success.js"></script>
<script src="scripts/controllers/feeds.js"></script>
<script src="scripts/controllers/ArchiveCtrl.js"></script>
<!-- endbuild -->

</body>
</html>

我的App.js很乱,因为它有我的所有指令/过滤器等等。但这里是:

'use strict';

/**
 * @ngdoc overview
 * @name showhausAngApp
 * @description
 * # showhausAngApp
 *
 * Main module of the application.
 */
angular
    .module('showhaus', [
        'ngAnimate',
        'ngCookies',
        'ngResource',
        'ngRoute',
        'ngSanitize',
        'ngTouch',
        'angularUtils.directives.dirPagination'
    ])
    .factory('loadingService', function () {
        var service = {
            requestCount: 0,
            isLoading: function () {
                return service.requestCount > 0;
            }
        };
        return service;
    })

    .factory('onStartInterceptor', function (loadingService) {
        return function (data) {
            loadingService.requestCount++;
            return data;
        };
    })

    .factory('delayedPromise', function ($q, $timeout) {
        return function (promise, delay) {
            var deferred = $q.defer();
            var delayedHandler = function () {
                $timeout(function () {
                    deferred.resolve(promise);
                }, delay);
            };
            promise.then(delayedHandler, delayedHandler);
            return deferred.promise;
        };
    })

    .factory('onCompleteInterceptor', function (loadingService, delayedPromise) {
        return function (promise) {
            var decrementRequestCount = function (response) {
                loadingService.requestCount--;
                return response;
            };
            return delayedPromise(promise, 0).then(decrementRequestCount, decrementRequestCount);
        };
    })

    .config(function ($routeProvider, $httpProvider, $locationProvider) {
        $routeProvider
            .when('/', {
                templateUrl: 'pages/main.html',
                controller: 'MainCtrl'
            })
            .when('/about', {
                templateUrl: 'pages/about.html',
                controller: 'AboutCtrl'
            })
            /*.when('/showpage', {
                templateUrl: 'pages/showpage.html',
                controller: 'ShowpageCtrl'
            })
            .when('/showpage/:city/:venue/', {
                templateUrl: 'pages/showpage.html',
                controller: 'ShowpageCtrl'
            })*/
            .when('/post', {
                templateUrl: 'pages/post.html',
                controller: 'PostCtrl'
            })
            .when('/success', {
                templateUrl: 'pages/success.html',
                controller: 'SuccessCtrl'
            })
            .when('/edit',{
                templateUrl: 'pages/edit.html',
                controller: 'EditCtrl'
            })
            .when('/feeds',{
                templateUrl: 'pages/feeds.html',
                controller: 'FeedsCtrl'
            })
            .when('/archivedOrDeleted', {
                templateUrl: 'pages/archivedOrDeleted.html',
                controller: 'ArchiveCtrl'
            })
            .otherwise({
                redirectTo: '/'
            });
        $httpProvider.responseInterceptors.push('onCompleteInterceptor');
        $locationProvider.hashPrefix('!');
    })

    .run(function ($http, onStartInterceptor) {
        $http.defaults.transformRequest.push(onStartInterceptor);
    })

    .factory('getSetCity', function () {
        var savedData = {};

        function set(data) {
            savedData = data;
        }

        function get() {
            return savedData;
        }

        return {
            set: set,
            get: get
        };
    })
    .factory('getSetVenue', function () {
        var savedData = {};

        function set(data) {
            savedData = data;
        }

        function get() {
            return savedData;
        }

        return {
            set: set,
            get: get
        };
    })
    .directive('numbersOnly', function () {
        return {
            require: 'ngModel',
            link: function (scope, element, attrs, modelCtrl) {
                modelCtrl.$parsers.push(function (inputValue) {
                    // this next if is necessary for when using ng-required on your input.
                    // In such cases, when a letter is typed first, this parser will be called
                    // again, and the 2nd time, the value will be undefined
                    if (inputValue === undefined) {
                        return '';
                    }
                    var transformedInput = inputValue.replace(/[^0-9]/g, '');
                    if (transformedInput !== inputValue) {
                        modelCtrl.$setViewValue(transformedInput);
                        modelCtrl.$render();
                    }

                    return transformedInput;
                });
            }
        };
    })
    .directive('ckEditor', [function () {
        return {
            require: '?ngModel',
            restrict: 'C',
            link: function(scope, elm, attr, ngModel) {
                var ck;
                ck = CKEDITOR.replace(elm[0]);//jshint ignore:line

                if (!ngModel){
                    return;
                }

                ck.on('pasteState', function() {
                    scope.$apply(function() {
                        ngModel.$setViewValue(ck.getData());

                    });
                });

                ngModel.$render = function() {
                    ck.setData(ngModel.$viewValue);
                };
            }
        };
    }])
    .directive('fileread', [function () {
        return {
            scope: {
                fileread: '='
            },
            link: function (scope, element) {
                element.bind('change', function (changeEvent) {
                    var reader = new FileReader();
                    reader.onload = function (loadEvent) {
                        scope.$apply(function () {
                            scope.fileread = loadEvent.target.result;
                        });
                    };
                    reader.readAsDataURL(changeEvent.target.files[0]);
                });
            }
        };
    }])
    .directive('chosen', function($timeout) {

        var linker = function(scope, element, attr) {

          $timeout(function () {
            element.chosen({
              placeholder_text_single: "-- select venue --",
              "disable_search_threshold": 5
            });
          }, 0, false);
        };

        return {
          restrict: 'A',
          link: linker
        };
      }).filter('startFrom', function() {
            return function(input, start) {
                start = +start; //parse to int
                return input.slice(start);
            }
        })
        .filter('unique', function() {
           return function(collection, keyname) {
              var output = [],
                  keys = [];

              angular.forEach(collection, function(item) {
                  var key = item[keyname];
                  if(keys.indexOf(key) === -1) {
                      keys.push(key);
                      output.push(item);
                  }
              });

              return output;
           };
        })
        .filter('startFrom', function () {
            return function (input, start) {
                if (input) {
                    start = +start;
                    return input.slice(start);
                }
                return [];
            };
        })
        .filter("isFeatured", function() {
          return function(input, pick) {
              var filtered = [];
              angular.forEach(input, function(item) {
                if(item.featured!=='' && pick.featured) {
                  filtered.push(item);
                }
                else if(!pick.featured){
                  filtered.push(item);
                }
              });
              return filtered;
          };
        })
        .filter("isFree", function(){
          return function(input, box){
              var filtered = [];
              angular.forEach(input, function(item){
                  if(item.price==0 && box.price){
                      filtered.push(item);
                  }
                  else if(!box.price){
                      filtered.push(item);
                  }
              });
              return filtered;
          }
        });

0 个答案:

没有答案