Seb
1
Hi, I see in the documentation that you can pass custom data as parameters along with a component this way :
MyComponentInstance: {
type: MyComponent,
someData,
}
And someData would then be accessible in MyComponent as this.someData.
I would like to pass this.someData to a child component but this seems to be undefined in the static _template :
static _template() {
return {
MyChildInstance: {
type: MyChild,
someData: this.someData,
}
}
}
Is there a way to achieve it?
Thank you!
The reason this won’t work is because _template()
is a static
method, so it doesn’t have access to this
context of your component instance.
In this case you could update the template in the _init()
method of your component by doing something like this:
_init() {
this.tag('MyChildInstance').someData = this.someData
}
2 Likes
Seb
3
Hi @michiel I just found out about this.bindProp and it achieves exactly what I want to do.
Here’s the same exemple with it :
static _template() {
return {
MyChildInstance: {
type: MyChild,
someDataInChild: this.bindProp(someData),
}
}
}
I found it by accident while looking at Lightning on GitHub : bindProp is not working with the `text` shorthand · Issue #283 · rdkcentral/Lightning · GitHub
Is there a reason why Lightning’s documentation doesn’t mention bindProp?
http://www.lightningjs.io/docs/#/what-is-lightning/index
Thank you
3 Likes