2016-11-23 79 views
0

非常新的行動電纜和角2.我不斷收到這個錯誤,訂閱類沒有找到:「MessagesChannel」,當運行rails服務器。我正在使用ng2-cable連接到我的rails api。角度2訂閱類沒有找到

我在科爾多瓦

import { NgModule } from '@angular/core'; 
import { IonicApp, IonicModule } from 'ionic-angular'; 
import { MyApp } from './app.component'; 
import { HomePage } from '../pages/home/home'; 
import { MessageData } from '../providers/message-data'; 
import { Ng2Cable, Broadcaster } from 'ng2-cable/js/index'; 

@NgModule({ 
    declarations: [ 
    MyApp, 
    HomePage 
    ], 
    imports: [ 
    IonicModule.forRoot(MyApp) 
    ], 
    bootstrap: [IonicApp], 
    entryComponents: [ 
    MyApp, 
    HomePage 
    ], 
    providers: [ MessageData, Ng2Cable, Broadcaster ] 
}) 
export class AppModule { 
    messages: any; 
    constructor(private ng2cable: Ng2Cable, private broadcaster:  Broadcaster){ 
    this.ng2cable.subscribe('http://localhost:3000/cable', 'MessagesChannel'); 


    } 

} 

Rails的MessagesChannel

​​

任何幫助表示讚賞採用了棱角分明2!

回答

0

希望這仍然有幫助:默認ActionCable頻道繼承ApplicationCable::Channel,這是在app/channels/application_cable文件夾內定義的。你從ApplicationCable::MessagesChannel繼承。除非您明確定義該父級,否則預計會發生以下情況:

class MessagesChannel < ApplicationCable::Channel 
    def subscribed 
    stream_from 'allmessages' 
    end 
end