gpt4 book ai didi

Angular 6 - browser-crypto.js :3 Uncaught ReferenceError: global is not defined

转载 作者:太空狗 更新时间:2023-10-29 18:06:34 28 4
gpt4 key购买 nike

我正在实现 socketjs。但是我遇到了以下错误。

Angular 6 Socket Error下面是我正在使用的 socket 和 stomp 包。

import * as SockJS from 'sockjs-client';
import * as Stomp from 'stompjs/lib/stomp.js';

提前致谢。

这是我的 Angular 代码-

import * as Socket from 'socket.io-client';
import * as Stomp from 'stompjs/lib/stomp.js';

initializeWebSocketConnection2(){

let ws = new Socket(this.serverUrl);

this.stompClient = Stomp.over(ws);
let that = this;
this.stompClient.connect({}, function(frame) {


that.stompClient.subscribe("/test", function(message){
if(message.body) {
console.log(message.body);
window.location.reload();
}
});


that.stompClient.subscribe("/operation", function(message){
if(message.body) {
console.log(message.body);
window.location.reload();

}
});

});

最佳答案

将它添加到你的 polyfills.ts 中

(window as any).global = window

首先你需要通过输入安装socket-client

npm install --save @types/socket.io

然后你可以像这样在你的组件或服务中导入 socket.io-client

import * as Socket from 'socket.io-client';

像这样改变你的代码

let ws = Socket(this.serverUrl);

关于 Angular 6 - browser-crypto.js :3 Uncaught ReferenceError: global is not defined,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51380166/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com