Reputation: 1088
I'm using angular v1.5 and changing from directives to component() and I'm facing a situation
I have this component hierarchy grandfather > father > grandson and I'm trying to make a method available inside grandson component() so I'm passing the method from grandfather through grandson but this doesn't work, someone can give me a clue? maybe show me what I'm doing wrong? :/
I put a bit of code here to explain what I'm doing: https://gist.github.com/WagnerMoreira/29ca7764eaa335784e06eccf8b0223cf
Upvotes: 0
Views: 126
Reputation: 8959
Typically it can be done using require
and, optional, $onInit
like so:
require: {
parent: '^nameOfParent'
}
Then in the controller that is making use of the inherited function you can initialize it like this:
vm.$onInit = init();
function init() {
vm.foo = vm.parent.foo();
}
Upvotes: 1