Almir Bijedić
Almir Bijedić

Reputation: 51

Webcomponents: attributeChangedCallback not fired

Here is a basic hello world web component. The attributeChangedCallback does not get triggered when the attribute "who" is changed. Check the fiddle

MyElementProto.attributeChangedCallback = function(attr, oldVal, newVal) {
    console.log('attributeChangedCallback triggered');
        if (attr === 'who') {
            this.setWho(newVal);
        }
    };

https://jsfiddle.net/y3kj81nz/5/

Upvotes: 1

Views: 1594

Answers (1)

Omri Aharon
Omri Aharon

Reputation: 17064

You need to use the setAttribute method:

window.changeWhoAttr = function() {
    var el = document.querySelector('#custom-tag');
    el.setAttribute('who', 'Universe'); // Instead of el.who = 'Universe'
    console.log('changeWhoAttr triggered');
}

Fiddle

Upvotes: 5

Related Questions