Notice: The Monaca & Onsen UI Community Forum is shutting down.

For Onsen UI bug reports, feature requests and questions, please use the Onsen UI GitHub issues page. For help with Monaca, please contact Monaca Support Team.

Thank you to all our community for your contributions to the forum. We look forward to hearing from you in the new communication channels.

[Solved] Uncaught TypeError: ons.compile is not a function

  • I have error on migrate my application to ons2(2.0.0 pre5) with this code

    function addElement (data){
    var el = "<ons-list ></ons-list>".toDOM(); // toDOM convert String to DOM element
        var li = '<ons-list-item onclick="api.execProg(this.config);">\
            <ons-ripple lo></ons-ripple>\
            <ons-icon rel="icon" icon="dot-circle-o" size="20px"></ons-icon>\
            <span rel="title">Make a Call</span>\
        for(var i in data.items){
            var e = li.toDOM();
            e.querySelector('[rel="title"]').innerText = data.items[i].title;
            e.querySelector('[rel="icon"]').setAttribute("icon",data.items[i].icon || 'dot-circle-o');
            e.querySelector("ons-list-item").config = JSON.stringify(data.items[i]);
        ons.compile(this) ; //Uncaught TypeError: ons.compile is not a function
    // Usage Ex. :'#myRoot'),{title:"Mon titre",icon:"circle",extra: "cool"})

    Error : Compile is not defined.

  • Do you have the above code called in an ons.ready() or is it how it is? While I am not an Angular expert, I believe compile is called in that function as documeted here:

  • @badlee You don’t need to run ons.compile in Onsen UI 2.0. The elements are Custom Elements and will automatically be compiled.

  • @argelius Even better! Its not used at all. lol.

  • @argelius it’s done, thank’s.