'Unknown Provider' 尝试在 MeanJS v0.4.1 应用程序中包含 angular-websocket

'Unknown Provider' trying to Include angular-websocket in a MeanJS v0.4.1 app

我在我正在处理的 MeanJS 应用程序的控制器中使用 angular-websocket 时遇到一些困难。

我的应用程序基于 MeanJS v0.4.1。

我第一次安装它是:

    bower install angular-websocket --save    

这创建了目录 /public/lib/angular-websocket

接下来我将它添加到/config/assets/default.js

    lib: {
      css: [
        ...
      ],
      js: [
        ...
        'public/lib/angular-websocket/angular-websocket.js'
      ],
      tests: ['public/lib/angular-mocks/angular-mocks.js']
    },

在我的 /modules/core/client/app/config.js 文件中,我将其添加为依赖项:

    var applicationModuleVendorDependencies = [
        ...
        'angular-websocket'
    ];

最后在我的 angular 模块中,

    angular.module('somemodule').controller('ModulenameController', ['$scope', '$http', '$stateParams', '$location', 'Authentication', 'SomeModule', 'ngWebSocket',
        function ($scope, $http, $stateParams, $location, Authentication, SomeModule, ngWebSocket) {

当我查看我的页面时,我可以在 Chrome 的开发人员工具的 "Sources" 选项卡中看到它作为源包含在内,

我正在尝试在我的控制器中将此文件与类似的东西一起使用:

    var dataStream = ngWebSocket('wss://www.somesite.com/realtime');

    dataStream.onMessage(function(message) {
        console.log("dataStream Message: " + message);
        $scope.orderBook = message;
    });

    dataStream.send('{"op":"subscribe", "args":"someargument"}');

但是,我的控制台显示以下错误:

Error: [$injector:unpr] Unknown provider: ngWebSocketProvider <- ngWebSocket <- ModuleNameController

我尝试过的一些事情:

  1. 更改参考名称
    根据文档 (https://www.npmjs.com/package/angular-websocket)

    angular.module('YOUR_APP', [
      'ngWebSocket' // you may also use 'angular-websocket' if you prefer
    ])
    

我试过使用 'ngWebSocket'、'angular-websocket',但我仍然遇到同样的问题。

  1. 我试着查看我的代码,看看是否可能这被重新定义为 angularJS 文档:

    https://docs.angularjs.org/error/$injector/unpr

指出此错误的原因可能是 'redefining a module using the angular.module API'。

如有任何帮助,我们将不胜感激。

工厂实际命名为$websocket,所以你应该这样做:

 angular.module('somemodule').controller('ModulenameController', ['$scope', '$http', '$stateParams', '$location', 'Authentication', 'SomeModule', '$websocket',
    function ($scope, $http, $stateParams, $location, Authentication, SomeModule, $websocket) {