Search code examples
javascriptpolymerpaper-elements

Polymer via javascript paper button


how to implement a polymer paper button via javascript? I'm trying something like this.

var newPaperButtonElement = document.createElement('paper-button');
    newPaperButtonElement.setAttribute('class','btn');
    newPaperButtonElement.setAttribute('on-tap','{{ test}}');


var newCoreIconElement = document.createElement('core-icon');
    newCoreIconElement.setAttribute('icon','remove-circle');
    newCoreIconElement.setAttribute('class','icon');
    newCoreIconElement.setAttribute('style', 'color: rgba(255, 0, 0, 0.42);')

    newPaperButtonElement.appendChild(newCoreIconElement);

But my function gets never called? Nothing happends. Using Polymer 0.5 atm...


Solution

  • You can't add binding imperatively. If you create the element imperatively you have to add/remove event handler imperatively

    newPaperButtonElement.addEventListener('tap', this.test);
    

    test might need to look differently depending on where the function is (your question doesn't provide context).

    I hope I got the syntax right, I don't use JS (only Dart).