【问题标题】:angular 2 and stomp: Can't resolve all parameters角度 2 和 stomp:无法解析所有参数
【发布时间】:2016-10-07 09:10:07
【问题描述】:

我一直有错误,并且已经看到了

错误:无法解析 DataComponent 的所有参数

我不知道如何调试它来自哪里。任何帮助或提示将不胜感激。

数据组件.ts

import { Component, OnInit, Inject } from '@angular/core';

import { Message, Client, Stomp } from 'stompjs';
import * as SockJS from 'sockjs-client';

@Component({
    selector: 'data',
    template: `
        <div id="raw">
            <h2>Messages</h2>
            <p>{{message}}</p>
        </div>
        `,
})
export class DataComponent implements OnInit, OnDestroy {
    constructor(private client : Client) { }

    mq_username = "guest";
    mq_password = "guest";
    mq_vhost    = "/";
    mq_url      = 'http://localhost:15674/stomp';
    mq_queue    = "/exchange/helloworld";

    public message: string;

     /** Callback on_connect to queue */
    public on_connect = () => {
        console.log('client', this.client);
        this.client.subscribe(this.mq_queue, function(message: Message) {
            this.message = message.body; 
        })
    }
    public on_connect_error(){
        console.log('connection failed');
    }

    ngOnInit() {
        this.client = Stomp.client(this.mq_url);
        this.client.connect(
            this.mq_username,
            this.mq_password,
            this.on_connect,
            this.on_connect_error,
            this.mq_vhost
        )
    }
}

tsconfig.ts 选项中,emitDecoratorMetadataexperimentalDecorators 都设置为 true。

systemjs.config 中的库以这种方式包含:

 System.config({
    paths: {
      'npm:': 'node_modules/'
    },
    map: {
      app: 'dist',

      // angular bundles
      [ANGULAR BUNDLES HERE]

      // other libraries
      'rxjs':                       'npm:rxjs',
      'sockjs-client': 'lib/sock-js/sockjs.min.js',
      'stompjs': 'node_modules/stompjs/lib/stomp.min.js',
    },
    [etc]

【问题讨论】:

    标签: angular stomp sockjs


    【解决方案1】:

    看起来 Client 不是 Angular 2 服务。

    如果是这样,那么你不能通过构造函数注入它。

    看看this,它使用的是早期版本的 angular 2,但它应该让您了解如何使其工作。

    【讨论】:

    • 我会尝试将其作为服务注入并返回并更新。非常感谢您的提示。
    • 当使用这个例子时,我得到一个类似core.umd.js:3462 EXCEPTION: Uncaught (in promise): SyntaxError: Failed to construct 'WebSocket': The URL's scheme must be either 'ws' or 'wss'. 'http' is not allowed.@Meireles 的错误我怎样才能允许 HTTP 方案?
    猜你喜欢
    • 2017-03-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-10-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多