[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>\ </ons-list-item>'; for(var i in data.items){ if(data.items[i].title){ 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]); el.appendChild(e); } } this.appendChild(el); ons.compile(this) ; //Uncaught TypeError: ons.compile is not a function api.applyColor(); }; // Usage Ex. : addElement.call(document.querySelector('#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: https://onsen.io/v2/docs/guide/angular1/index.html#utility-functions
-
@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.