非常新的动作电缆和角度2.我一直收到此错误,未找到订阅类:" MessagesChannel",运行rails服务器时。我正在使用ng2-cable连接到我的rails api。
我在cordova上使用角度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
class MessagesChannel < ApplicationCable::MessagesChannel
def subscribed
stream_from 'allmessages'
end
end
感谢任何帮助!
答案 0 :(得分:0)
希望这仍有帮助:默认的ActionCable频道继承自ApplicationCable::Channel
文件夹中定义的app/channels/application_cable
。您继承自ApplicationCable::MessagesChannel
。除非您明确定义了该父类,否则人们期望具有以下内容:
class MessagesChannel < ApplicationCable::Channel
def subscribed
stream_from 'allmessages'
end
end