“未知供应商”试图将angular-websocket包含在一个MeanJS v0.4.1应用程序中。

时间:2020-12-24 01:09:43

I am having a bit of difficulty using angular-websocket in a controller in a MeanJS application I am working on.

在我正在开发的一个MeanJS应用程序中,我在控制器中使用angular-websocket时有一点困难。

My Application is based on MeanJS v0.4.1.

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

I first installed it with:

我首先安装了:

    bower install angular-websocket --save    

This created the directory /public/lib/angular-websocket

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

Next I added it to /config/assets/default.js

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

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

In my /modules/core/client/app/config.js file I have added it as a dependency:

在我/模块/核心/客户机/应用程序/配置。我添加了js文件作为一个依赖项:

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

And finally in my angular module itself,

最后在我的角模中,

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

When I go to view my page I can see in the "Sources" tab of Chrome's Developer tools that it is included as a source,

当我去查看我的页面时,我可以在Chrome开发工具的“源代码”选项卡中看到它作为源代码包含,

I am trying to use this file with something like this in my controller:

我试着在我的控制器中使用这个文件

    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"}');

However, my console shows the following error:

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

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

Some of the things I have tried:

我尝试过的一些事情:

  1. Changing The Reference Name
    As per the documentation (https://www.npmjs.com/package/angular-websocket)

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

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

I've tried using 'ngWebSocket', 'angular-websocket', but I still get the same issue.

我尝试过使用“ngWebSocket”,“angular-websocket”,但我还是遇到了同样的问题。

  1. I've tried looking through my code to see if maybe this was being redefined as the angularJS documentation here:

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

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

    https://docs.angularjs.org/error/ $喷射器/ unpr

states that a cause of this error could be 'redefining a module using the angular.module API'.

声明这个错误的原因可能是“使用角度重新定义一个模块”。模块API”。

Any help would be greatly appreciated.

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

1 个解决方案

#1


2  

The factory is actually named $websocket, so you should do as follows:

工厂实际上被命名为$websocket,所以你应该做如下:

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

#1


2  

The factory is actually named $websocket, so you should do as follows:

工厂实际上被命名为$websocket,所以你应该做如下:

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