【问题标题】:angular 2 subscription class not found找不到角度2订阅类
【发布时间】:2016-11-23 15:35:50
【问题描述】:

非常新的动作电缆和角度 2。我一直收到此错误,未找到订阅类:“MessagesChannel”,运行 rails 服务器时。我正在使用 ng2-cable 连接到我的 rails api。

我在 Cordova 上使用 Angular 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 消息频道

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

感谢任何帮助!

【问题讨论】:

    标签: ruby-on-rails angular action actioncable


    【解决方案1】:

    希望这仍然有帮助:默认 ActionCable 频道继承自 ApplicationCable::Channel,它在 app/channels/application_cable 文件夹中定义。你继承自ApplicationCable::MessagesChannel。除非您明确定义了该父类,否则您会期望拥有以下内容:

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2016-10-09
      • 2016-12-24
      • 1970-01-01
      • 2021-01-10
      • 1970-01-01
      • 1970-01-01
      • 2017-01-10
      • 2017-06-25
      相关资源
      最近更新 更多