I'm building a widget that depends on Angular along with a widget builder tool. The builder used Angular with ngApp
attached to the html
tag of the document.
When I load up the widget within the widget builder, I get the following error:
Error: [ng:btstrpd] App Already Bootstrapped with this Element '<div class="company-widget" id="widget-app" data-company="demoCorp">'
Here is the bootstrap function:
angular.bootstrap('#widget-app', ["myWidget"]);
For all intents and purposes, the rest of the myWidget
app is a pretty standard mix of controllers and services.
I was following along with this blog post on how to allow multiple ngApp
directives in a single page, however I didn't realize until after I set this thing up that it says right at the end of the blog post that you can't nest apps, which is what's happening here, and what may occur on a small number of sites that use this widget.
I can't redesign the widget-builder and I can reasonably assume that for any Angular sites where the widget is embedded, the host site will attach ngApp
to the html
tag.
My question is, is there a way to get around this limitation, even if it's a hacky solution? Is it possible to check if the page already has an app and inject the myWidget
app into the host app as a dependency?
script
block that the boostrapping happens in? You said you can't redesign the widget builder, but are there any modules you can piggy back on? – Nuno