我正在将一个类导入另一个类,并且我想在Angular中访问其非静态属性,但是我无法做到这一点。
这是我正在使用的代码:
Websocket.config.ts
export class WebSocketConfig implements OnInit{
auth$: Subscription;
userInfo: UserInfo;
user_name: string;
username: string;
constructor(private authService: AuthorizationService){
}
ngOnInit() {
this.username = this.getUserName();
}
getUserName(): string{
this.auth$ = this.authService.getUserInformation().subscribe(result => {
this.userInfo = result;
this.user_name = this.userInfo.user_id;
});
return this.user_name;
}
public static uri: string = "wss://localhost:9093/powerme-notification-websocket/websocket";
public static notification_topic : string = '/user/topic/releaseLock';
}
shared.module.ts
const stompConfig : StompConfig = {
url : WebSocketConfig.uri,
headers: {client_id: WebSocketConfig.username},
heartbeat_in: 0,
heartbeat_out: 20000,
reconnect_delay: 5000,
debug: false
}
在WebSocketConfig.username中,它说“属性用户名在类型“ typeOf WebSocketConfig上不存在”。
我正在使用Stomp和websocket发送通知。