AngularJS刷新页面间歇性地抛出一个未被捕获的对象

时间:2014-06-09 23:41:31

标签: javascript angularjs

我目前有一个路由文件正在加载控制器和部分html到达索引时。我正在使用http-server和angular-seed项目附带的默认配置。所以我使用npm start启动服务器。

问题是我第一次在启动服务器后点击页面时,页面似乎正常加载。但是如果我坐在那里刷新一堆页面,我就会开始得到一个看起来像这样的未被捕获的对象错误,

Uncaught object angular.js:78
    (anonymous function) angular.js:78
    (anonymous function) angular.js:3948
    forEach angular.js:320
    loadModules angular.js:3909
    createInjector angular.js:3849
    doBootstrap angular.js:1510
    bootstrap angular.js:1525
    (anonymous function) app.js:12
    n.Callbacks.j jquery.js:3073
    n.Callbacks.k.fireWith jquery.js:3185
    n.extend.ready jquery.js:3391
    I jquery.js:3407

app.js

"use strict";

define("app", ["angular", "routes", "angular-resource", "angular-route", "jQuery"], function (angular) {
    var app = angular.module("app", [
        "ngResource", 
        "ngRoute", 
        "app.customerApp"
    ]);

    angular.element().ready(function() {
        angular.bootstrap(document, ["app"]);
    });

    return app;
});

routes.js

"use strict";

require(["app", "components/app/app-ctrl", "components/customer/customer-ctrl"], function(app) {
    return app.config(["$routeProvider", "$resourceProvider", 
    function ($routeProvider, $resourceProvider) {
        $routeProvider.when("/", {
            controller: "CustomerCtlr", 
            templateUrl: "/app/partials/customer.html"
        }).otherwise({redirectTo: '/'});
    }]);
});

客户ctrl.js

'use strict';

define("customerApp", ["angular", "angular-resource"], function(angular) {
    var customerApp = angular.module('app.customerApp', ["ngResource"]);
    return customerApp;
});

require(["customerApp"], function(customerApp) {
    customerApp.controller("CustomerCtlr", ["$scope", function ($scope) {

    }]);
});

我通过在app.js,routes.js和每次以不同顺序加载的控制器中放入console.logs来发现。为什么会这样? RequireJS应该会阻止它。

0 个答案:

没有答案