I was wondering what is the best way to pass functions down through 2 or more levels of components? There's no simple way of skipping the function wrap when using '&' bindings?
Here's an use case:
angular.module('app', []).component('app', {
controller: class AppController {
doSomething (data) {}
},
template: `
<sub-component on-do-something="$ctrl.doSomething(data)">
</sub-component>
`
})
ps: I'm using ngRedux, so such scenario is very common
EDIT:
The problem is: for the code above to work, each inner component controller would look like this:
.component('subComponent', {
bindings: {
doSomething: '&'
},
controller: function SubComponentController () {
this._doSomething = param => this.doSomething({data: param});
},
template: `
<inner-component do-something="$ctrl._doSomething(data)">
</inner-component>
`
});
.component('innerComponent', {
bindings: {
doSomething: '&'
},
controller: function InnerComponentController () {
this._doSomething = param => this.doSomething({data: param});
},
template: `
<sub-inner-component do-something="$ctrl._doSomething(data)">
</sub-inner-component>
`
});
And then I'd have to pass down _doSomething
instead of doSomething
directly.
ps: I'm not using transclusion here