Luiz E.
Luiz E.

Reputation: 7229

component cannot find action

I have a component that has a text field, like this

<div>
    {{input type='text' insert-newline='postMessage' class="form-control" autofocus="true"}}
    <input type="hidden" name="uid" value={{room.uid}}/>
</div>

the component that have this snippet, lives inside a route called room

export default Ember.Route.extend({
  model(params){
    this.store.findRecord('room', params.uid);
  }
});

to handle the action in the input, I created a controller for the room: app/controllers/room.js

import Ember from 'ember';

export default Ember.Controller.extend({
  actions: {
    postMessage(params){
      console.log(params);
    }
  }
});

but when I hit enter, I get this error:

Uncaught Error: <chathub-ember@component:chat-room::ember1071> had no action handler for: postMessage

I tried to put this action in the route as well and didn't worked

Upvotes: 0

Views: 640

Answers (1)

xcskier56
xcskier56

Reputation: 621

In the room.hbs file,

{{my-component myAction='postMessage'}}

and then in my-component.js

import Ember from 'ember';

export default Ember.Component.extend({
  actions: {
    postMessage(params) {
      this.sendAction('myAction', params);
    }
  }
})

Upvotes: 1

Related Questions