如何配置在装载时的AngularJS应用程序? [英] How to configure an AngularJS app at load time?

查看:132
本文介绍了如何配置在装载时的AngularJS应用程序?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想要做这样的事情(但显然不是这样就是这样,因为此功能不会以这种方式工作)

I want to do something like this (but obviously not this exactly, because this function doesn't work this way)

angular.bootstrap( $("#myelement"), ['myModule'], {foo: bar} );

我想在配置对象来传递,因为我们可能希望应用程序的多个实例页面上,通过不同的设置,等等。所有我能想到的是丑陋的解决方法。我想最好的事情是我重写自己制造的选项服务,但我仍然无法找出正确的方式做到这一点(简洁)。

I want to pass in a configuration object, since we may want to have more than one instance of the app on a page, with different settings, etc. All I can think of are ugly workarounds. I'm thinking the best thing would be to override an "Options" service of my own making, but I still can't figure out the proper way to do that (tersely).

在此先感谢!

推荐答案

你怎么样尝试是这样的:

How about you try something like this:

angular.module('configFoo', []).run(function() {});

angular.module('configBar', []).run(function() {});

angular.bootstrap(myEl, ['myModule', 'configFoo']);

angular.bootstrap(myOtherEl, ['myModule', 'configBar']);

http://docs.angularjs.org/api/angular.Module 所有可用的模块方法(你可能只在.RUN()和感兴趣的.config())

http://docs.angularjs.org/api/angular.Module for all available module methods (you're probably only interested in .run() and .config())

这篇关于如何配置在装载时的AngularJS应用程序?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆