角度模块不注入

时间:2016-12-23 15:20:08

标签: javascript ruby-on-rails angularjs

我的应用程序在开发或测试模式下运行正常,无论rails s做什么,但在生产模式下运行时不起作用 我在浏览器中收到以下错误

X GET http://localhost:4000/assets/application-bee14c2d11d9c46d50378b54dd87850181256a24c05d6ed2e72c0487fc775f86.js
X GET http://localhost:4000/assets/application-c7fa74d0d86da1dddcd65188a0ad91600d0d55a1be66ba476307822b2d36848b.css

(由于某种原因也无法在端口3000上运行,但lsof -i tcp:3000没有产生任何结果,也许这是相关的?我得到了

Exiting
/Users/jrogers2/.rvm/gems/ruby-2.2.3/gems/puma-3.6.2/lib/puma/binder.rb:266:in 'initialize': Address already in use - bind(2) for "::1" port 3000 (Errno::EADDRINUSE)
    from /Users/jrogers2/.rvm/gems/ruby-2.2.3/gems/puma-3.6.2/lib/puma/binder.rb:26

我被告知这是一个手动依赖注入问题,但我不相信,因为我经常环顾四周并尝试了许多不同的格式。但是这里有我的代码的一些例子以及下面的完整回购。

// app.js
(function(){
  'use strict';
  angular
    .module('app', ['templates', 'ui.router', 'Devise', 'ngResource', 'ngMessages', 'infinite-scroll', 'ngFileUpload'])
    .run(['Auth', function(Auth){
      Auth.currentUser()
    }])
}())

//application.js
//= require jquery
//= require angular
//= require angular-devise
//= require angular-messages
//= require angular-ui-router
//= require angular-resource
//= require bootstrap-sprockets
//= require moment
//= require angular-rails-templates
//= require ngInfiniteScroll
//= require ng-file-upload
//= require ng-file-upload-shim
//= require_tree .

// routes.js
(function(){
  'use strict';
  angular
    .module('app')
    .config(['$stateProvider', '$urlRouterProvider', function($stateProvider, $urlRouterProvider){
      $stateProvider
        .state('login', {
          url: '/',
          templateUrl: 'views/login.html',
          controller: 'loginController as loginCtrl',
          onEnter: ['$state', 'Auth', function($state, Auth){
            Auth.currentUser().then(function(data){
              $state.go('list', {id: data.list.id})
            })
          }]
        })
      $stateProvider
        .state('userPurchases', {
          url: '/users/:id/purchases',
          templateUrl: 'views/purchases.html',
          controller: 'purchaseController as purchaseCtrl',
          onEnter: ['$state', 'Auth', function($state, Auth){
            if (!Auth._currentUser){
              $state.go('login')
            }
          }]
        })

// listController.js
(function(){
  'use strict';
  var listController = ['$scope', 'Auth', '$stateParams', 'itemFactory', 'listFactory', function($scope, Auth, $stateParams, itemFactory, listFactory){
    var listCtrl = this;
    Auth.currentUser().then(function(data){
      $scope.currentUser = data;
    });
    $scope.itemsCounter = 0;
    $scope.list = listFactory.get({id: $stateParams.id});
    $scope.items = [];
    $scope.createItem = function(input){
      input.plzrender = 'list';
      input.items.list_id = $scope.currentUser.list.id;
      itemFactory.save(input).$promise.then(function(response){
        $scope.list = response;
      });
    }
    $scope.deleteItem = function(item){
      item.plzrender = 'list';
      itemFactory.delete(item).$promise.then(function(response){
        $scope.list = response;
      });
    }
    $scope.disableInfinite = false;
    $scope.loadMore = function(list){
      if ($scope.list.$resolved) {
        for (var i = 0; i < 10; i++) {
          $scope.items.push($scope.list.items[$scope.itemsCounter]);
          $scope.itemsCounter += 1;
          if ($scope.itemsCounter >= $scope.list.items.length) {
            $scope.disableInfinite = true;
            break;
          }
        }
      }
    }
    $scope.list.$promise.then(function(response){
      $scope.loadMore();
    });
  }];
  angular
    .module('app')
    .controller('listController', listController)
}())

github repo:https://github.com/jd2rogers2/presently

1 个答案:

答案 0 :(得分:0)

这绝对看起来像是一个JavaScript缩小问题。尝试在production.rb中禁用资产压缩(仅适用于您的JS)。您可以参考this question获取有关如何执行此操作的更多帮助。

我相信这可以解决你的问题。但根据我的进一步分析,我在缩小的JS for UI路由器中看到了以下代码:

function() {
  "use strict";
  angular.module("app").config(function(e, t) {
    e.state("login", {
        url: "/",
        templateUrl: "views/login.html",
        controller: "loginController as loginCtrl",
        onEnter: function(e, t) {
          t.currentUser().then(function(t) {
            e.go("list", {
              id: t.list.id
            })
          })
        }
      }),
      e.state("userPurchases", {
        url: "/users/:id/purchases",
        templateUrl: "views/purchases.html",
        controller: "purchaseController as purchaseCtrl",
        onEnter: function(e, t) {
          t._currentUser || e.go("login")
        }
      }).state("userEvents", {
        url: "/users/:id/events",
        templateUrl: "views/events.html",
        controller: "eventController as eventCtrl",
        onEnter: function(e, t) {
          t._currentUser || e.go("login")
        }
      }).state("userProfile", {
        url: "/users/:id",
        templateUrl: "views/profile.html",
        controller: "profileController as profileCtrl",
        onEnter: function(e, t) {
          t._currentUser || e.go("login")
        }
      }).state("userProfileEdit", {
        url: "/users/:id/edit",
        templateUrl: "views/editProfile.html",
        controller: "editProfileController as editProfCtrl",
        onEnter: function(e, t) {
          t._currentUser || e.go("login")
        }
      }),
      e.state("userFriends", {
        url: "/users/:id/friends",
        templateUrl: "views/friends.html",
        controller: "friendshipController as friendshipCtrl",
        onEnter: function(e, t) {
          t._currentUser || e.go("login")
        }
      }),
      e.state("list", {
        url: "/list/:id",
        templateUrl: "views/list.html",
        controller: "listController as listCtrl",
        onEnter: function(e, t) {
          t._currentUser || e.go("login")
        }
      }),
      e.state("listItemEdit", {
        url: "/list/:list_id/items/:item_id/edit",
        templateUrl: "views/items/edit.html",
        controller: "itemController as itemCtrl",
        onEnter: function(e, t) {
          t._currentUser || e.go("login")
        }
      }).state("listItemShow", {
        url: "/list/:list_id/items/:item_id",
        templateUrl: "views/items/show.html",
        controller: "itemController as itemCtrl",
        onEnter: function(e, t) {
          t._currentUser || e.go("login")
        }
      }),
      t.otherwise("/")
  })
}()

并且没有提到et在哪里。我认为这应该是你的罪魁祸首。