2016-10-07 6 views
0

を解決できません。どんな助けやヒントもありがとう。 emitDecoratorMetadataexperimentalDecoratorsの両方がtrueに設定されているtsconfig.tsオプションで角度2とストンプ:私が持ってエラー続ける、と私はどちらかどこから来て、それをデバッグすることができますかわからない</p> <blockquote> <p>Error: Can't resolve all parameters for DataComponent</p> </blockquote> <p>ことを見てきたすべてのパラメータ

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 
     ) 
    } 
} 

そして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] 

答えて

1

クライアントは角2サービスではないように見えます。

この場合、コンストラクタには挿入できません。

thisをご覧ください。これは、以前のバージョンの角度2を使用していますが、動作させる方法のアイデアを与えるはずです。

+0

私はサービスとしてそれを注入しようとして戻って、更新してください。ヒントに感謝します。 –

+0

この例では、 'core.umd.js:3462 EXCEPTION:Uncaught(promise)のようなエラーが出ます:SyntaxError: 'WebSocket'の作成に失敗しました:URLのスキームは 'ws'または 'wss'でなければなりません。 'http'は許可されていません。 ' @Meireles HTTPスキームを許可するにはどうしたらいいですか? –

関連する問題

 関連する問題