javascript - ReferenceError : SockJS is not defined, 无法将模块导入 Angular

标签 javascript angularjs angular-components sockjs

我正在使用 Angular 1.5.11,并使用 sockjs 和 stomp 连接到 Web 套接字。 Angular 项目对 stomp 和 sockjs-client 有一个 Bower 依赖,但是当我使用

var socket = new SockJS('http://localhost:8999/socket-app');

我收到一条错误消息,提示“SockJS”未定义。我使用 gulp 进行构建和服务。我是否必须在项目中的某个位置显式声明或导出它?

当我将所有代码放入带有 sockjs 和 Angular 代码的简单单文件 html 中时,同样的事情也会发生。

我的目录结构如下:

enter image description here

编辑:要添加更多详细信息,我有以下 Bower 依赖项:

enter image description here

安装 Bower 后,我在组件文件夹中看到它们。所以我有所需的依赖项,但我想仍然缺少一些东西。

最佳答案

可能,您需要的是 sockjs-client,而不是 sockjs。尝试使用 Bower sockjs-client 安装

关于javascript - ReferenceError : SockJS is not defined, 无法将模块导入 Angular,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47621678/

相关文章:

javascript - HTML5 localStorage 将新数据附加到已存在的键

php - 页面刷新后自动激活Bootstrap模式

angularjs - Angular UI-Router 重定向登录用户远离登录路由

javascript - 从 Controller Angularjs 调用链接函数

javascript - AngularJS:使用 ngRoute 路由时未加载组件 Controller

javascript - 如何在 Jquery 中使用 href 标记和 URL 发送变量

javascript - 根据选择选项更新输入值

angularjs - 使用带有 Ionic 1 的 FCM 推送通知的多行文本消息

Angular 2 Dart : How to share variables between parent with router and child components?

javascript - 使用包含多个绑定(bind)的组件配置 ui-router