Answer the question
In order to leave comments, you need to log in
How to handle event in child component, ember.js?
Hello.
There is a component inside which there are a bunch of others, an event can occur on this heap, and I want to handle this event with one, the most important component. Tell me how to do it? Those. it is necessary to launch an event from the child component in the parent, saving the information where the event came from.
export default Ember.Component.extend({
actions: {
open(obj){
console.log('OPEN');
},
});
export default Ember.Component.extend({ // дочерние компоненты
alarm(){
this.send('open', this);
},
});
Answer the question
In order to leave comments, you need to log in
{{child-component open=(action "open")}}
like this?
emberjs.com/api/classes/Ember.Component.html#metho...
test(obj){
console.log(obj);
}
open(){
console.log('child fired');
this.sendAction('test', this);
}
export default Ember.Component.extend({
actions: {
open(obj){
console.log('OPEN');
},
},
});
export default Ember.Component.extend({ // дочерние компоненты
alarm(){
this.sendAction('alarm', this);
},
});
{{#parent-component as |parent|}}
{{child-component alarm=(action "open" target=parent)}}
{{/parent-component}}
And there are no options not to explicitly pull the event through the components, if there is a large tree of them, each one must be called with the transfer of an action ...
I thought to do it through the service, but you can transfer the event to the service, but from the service - again a problem.
in general, while I've done a crutch, it's a shame, but it works.
export default Ember.Service.extend({
stack_view:[],
open(obj){
},
});
export default Ember.Component.extend({
manager: Ember.inject.service(),
init:function(){
this.get('manager').set('open', this.open);
},
actions: {
open(obj){
console.log('OPEN');
},
});
export default Ember.Component.extend({ // дочерние компоненты
manager: Ember.inject.service(),
actions: {
open(){
this.get('manager').open(this);
},
}
});
had similar problems before, you need to update to the latest revisions, they no longer have these failures
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question