2016-11-23 65 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