I am missing a `bootstrap` method for non-angular apps
-
I think my use case is not that exotic: I just need to preparse my
ons-template
s to have some placeholders replaced on them (specifically, I am talking about i18n strings). I am not using Angular, so that thebootstrap
global function is not available.I include onsenui.js as a normal file so that I don’t have a way to put it “in pause”, load my strings (via an ajax call), change the templates and then let it do its job as usual, using the now “translated” templates.
I also tried loading onsenui (beta 5) via
require()
but it apparently doesn’t work. I get some weird “jsmutationobserver” error. I am using webpack and not browserify, so maybe that’s the problem.Anyway, I understand that this not a simple problem to solve, since by default onsenui bootstrap itself automatically and changing this default is not possible of course.
Maybe, adding a class to the
body
or an attribute to theons-navigator
?Thanks for listening :)
P.S.: my current solution is to compile those strings on-the-fly on the
init
event of the navigator (so, each time I am about to show a page). I still have problem bootstrapping, because of the asynchronous ajax call to fetch the language file but I can deal with it.
-
@claudioc Well,
ons.bootstrap
is just a synonym ofangular.module('myApp')
, so of course there is no need to use it in Onsen 2.0 core.About your issue, I guess you can start your navigator without pages (i.e remove
page
attribute) and dopushPage
orresetToPage
whenever your first template is ready. This looks like a very simple solution so perhaps I’m missing something about your problem.By the way, I’d recommend you to update to the latest beta. Many things have changed since beta.5.
-
You’re right. I forgot that I had the
page
attribute on the navigator :)This only solves part of the problem though, because once the
ons.ready
is fired, myons-template
s in the DOM are empty, like they have been “consumed” (and it’s OK, I guess ONS stores them in memory, out of the DOM). So it’s too late for me to replace the strings inside them.I guess I will stick with changing the strings on each page’s
init
event handler. No big deal.Thanks!
(I’ll update to the latest beta right now)
-
@claudioc
ons-template
removes its content and stores it in an internal variable to avoid ID collision and other stuff. I think you would prefer to usepageHTML
parameter instead of the normalpage
one. That way you don’t need to modify the templates. In case you really want to useons-template
and modify it, the variable where the content is stored is calledtemplate
(original, I know).document.getElementById('my-page-template').template
.