angular 2 and stomp: 无法解析所有参数

angular 2 and stomp: Can't resolve all parameters

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

Error: Can't resolve all parameters for DataComponent

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

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 都设置为真。

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]

Client 似乎不是 angular 2 服务。

如果是这种情况,则不能通过构造函数注入它。

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