angular.bootstrap运行多个应用程序的角度多个、应用程序、角度、angular

2023-09-14 00:16:49 作者:6.Review(旧爱)

这不是一个Twitter的引导问题...

我有一个需要单独的角度应用加载一个用例。

I have a use case that requires the loading of separate angular applications.

,它是可行的。但是,我无法得到它的工作。

Based on several stack overflow questions and this google thread, it's doable. However, I can't get it to work.

综观文档:

http://docs.angularjs.org/api/angular.bootstrap

看起来你需要提供元素(如何获得元素上的手柄),然后如何配合回配置,控制器等而如何将与路线这项工作?看来,如果一个应用程序使用,否则和其他用途,否则,第二个将只覆盖第一?

It looks like you need to provide the element (how to get a handle on the element?), and then how to tie it back to config, controllers, etc. And how would this work with routes? Seems if one app uses otherwise and the other uses otherwise, the second would just override the first?

谢谢!

推荐答案

要抢你的应用程序(S)引用,你可以做线沿线的东西:

to grab references to your app(s), you can do something along the lines of:

var first = document.getElementById('firstapp-id');
var second = document.getElementById('secondapp-id');

angular.bootstrap(angular.element(first), ['firstapp']);
angular.bootstrap(angular.element(second), ['secondapp']);

其中firstapp'和'secondapp是模块/应用程序名称和firstapp-ID和secondapp-ID是容器div的每个应用程序(或您最喜欢的DOM元素)的ID的。只要定义以通常的方式您的应用程序:

where 'firstapp' and 'secondapp' are module/app names, and 'firstapp-id' and 'secondapp-id' are the id's of the container div's for each app (or your favorite DOM element). just define your apps in the usual manner:

var firstapp = angular.module('firstapp', []);
var secondapp = angular.module('secondapp', []);