我已经定义了使用ng-stomp和Angular7的模块。
除了我构建应用程序并将其部署在Tomcat中之外,它的工作效果都很好:
问题是生产中的代码已缩小...
但是我知道加载模块时会发生这种情况,所以我有代码的注释和取消注释部分以查找错误:它来自提供者部分:
这是模块:
import {NgModule} from '@angular/core';
import {MaterialModule} from '../app.module';
import {CommonModule} from '@angular/common';
import {FormsModule, ReactiveFormsModule} from '@angular/forms';
import {DataTablesModule} from 'angular-datatables';
import {RouterModule} from '@angular/router';
import {CommunicationRoutes} from './communication.routing';
import {AlertesComponent} from './alertes/alertes.component';
import {MediasComponent} from './medias/medias.component';
import {ModalMediaComponent} from './medias/modal.media.component';
// Import your library
import { ImageViewerModule } from 'ng2-image-viewer';
import {WebsocketComponent} from './chat/websocket.component';
import { InjectableRxStompConfig, RxStompService, rxStompServiceFactory } from '@stomp/ng2-stompjs';
import {myRxStompConfig} from './chat/rx-stomp-config';
import {NotesComponent} from './notes/notes.component';
@NgModule({
imports: [
CommonModule,
RouterModule.forChild(CommunicationRoutes),
FormsModule,
DataTablesModule,
MaterialModule,
ReactiveFormsModule,
ImageViewerModule,
NgChatModule,
],
declarations: [
AlertesComponent,
MediasComponent,
NotesComponent,
WebsocketComponent,
ModalMediaComponent
],
entryComponents: [
ModalMediaComponent
],
providers: [
{
provide: InjectableRxStompConfig,
useValue: myRxStompConfig
},
{
provide: RxStompService,
useFactory: rxStompServiceFactory,
deps: [InjectableRxStompConfig]
}
]
})
export class CommunicationModule {}
当我评论提供者部分时,它会起作用
我编码的唯一部分是myRxStompConfig:
import { InjectableRxStompConfig } from '@stomp/ng2-stompjs';
import {MyJarviaServices} from '../../services/myjarvia.services';
import {environment} from '../../../environments/environment';
let myJarviaServices: MyJarviaServices;
export const myRxStompConfig: InjectableRxStompConfig = {
// Which server?
brokerURL: 'ws://' + environment.wsUrl,
// Headers
// Typical keys: login, passcode, host
connectHeaders: {
login: 'guest',
passcode: 'guest'
},
// How often to heartbeat?
// Interval in milliseconds, set to 0 to disable
heartbeatIncoming: 0, // Typical value 0 - disabled
heartbeatOutgoing: 0, // Typical value 20000 - every 20 seconds
// Wait in milliseconds before attempting auto reconnect
// Set to 0 to disable
// Typical value 500 (500 milli seconds)
reconnectDelay: 2000,
// Will log diagnostics on console
// It can be quite verbose, not recommended in production
// Skip this key to stop logging to console
debug: (msg: string): void => {
//console.log(new Date(), msg);
}
};
请参阅:https://stomp-js.github.io/guide/ng2-stompjs/2018/11/04/ng2-stomp-with-angular7.html
我通过在index.html中更新global来进行尝试:
<head>
<base href='/'>
<meta charset="utf-8" />
<link rel="apple-touch-icon" sizes="76x76" href="./assets/img/apple-icon.png" />
<link rel="icon" type="image/png" href="./assets/img/favicon.png" />
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1" />
<title>MyApp</title>
<meta content='width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0' name='viewport' />
<meta name="viewport" content="width=device-width" />
<script type="application/javascript"> var global = window; </script>
</head>
但没有任何变化。...我该如何解决此生产错误?