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.

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-templates to have some placeholders replaced on them (specifically, I am talking about i18n strings). I am not using Angular, so that the bootstrap 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 the ons-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.


  • Onsen UI

    @claudioc Well, ons.bootstrap is just a synonym of angular.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 do pushPage or resetToPage 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, my ons-templates 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)


  • Onsen UI

    @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 use pageHTML parameter instead of the normal page one. That way you don’t need to modify the templates. In case you really want to use ons-template and modify it, the variable where the content is stored is called template (original, I know). document.getElementById('my-page-template').template.