jkorhonen
jkorhonen

Reputation: 11

Can I bind an attribute to web component?

If I have global @observable var myObservable = 'foo'; I can pass it to web component like this:

    <x-component my-attribute="{{myObservable}}"></x-component>

and it's passed to XComponent.myAttribute before the WebComponent.created() lifecycle method. The problem is when I change the myObservable = 'bar'; the XComponent.myAttribute isn't changed.

Is this type of binding possible somehow? Or is the WebComponent.attributeChanged(...) the key for this (when it's implemented by the Web UI team)?

Upvotes: 1

Views: 100

Answers (1)

Kai Sellgren
Kai Sellgren

Reputation: 30192

I believe you can use bind- for this.

Give this a try:

<x-component bind-my-attribute="myObservable"></x-component>

Also, remember to specify @observable for my-attribute, too.

Upvotes: 1

Related Questions