2

My app context is generated in the run-time, on onsen 1.3 i was using this function to generate the HTML and compile it,

$scope.generateFrom = function (div) {
        var el = div;
        var html = HTMLGenerator.getHTML();
        el.innerHTML = html;
        ons.compile(el);
    }

But after upgrading to onsen 2/Angular i am getting this error

"Error: First argument must be an instance of HTMLElement.

Any suggestions to fix this issue ?

Omar Hassan
  • 727
  • 1
  • 11
  • 24

1 Answers1

0

As @fran-dios said on Onsen's forum, using Onsen 2.0 doesn't require you to compile elements manually. You asked for a code example of dynamically adding elements, so please see the below code to add list items to a list:

var onsItem= document.createElement('ons-list-item');
       onsItem.setAttribute('modifier', "chevron");
       onsItem.setAttribute('onclick', "functionName()");
       onsItem.innerHTML = '<img src="" alt="something here" />';
document.getElementById('listID').appendChild(onsItem);
Munsterlander
  • 1,356
  • 1
  • 16
  • 29