您将如何将“调试”与“发布”参数传递给 Aurelia 应用程序?
就我而言,我在 MVC 应用程序中安装了 Aurelia。我想根据我的 web.config 值为 Aurelia 配置一些参数(URL 等)。
有没有办法我可以这样做:
<script src="~/Aurelia/jspm_packages/system.js"></script>
<script src="~/Aurelia/config.js"></script>
<script>
System.import('aurelia-bootstrapper', @this.ViewBag.MyArgs);
</script>
Where this.ViewBag.MyArgs会包含从 MVC 加载的参数吗?
然后我可以在我的 Aurelia 服务中使用这些参数,例如
this.httpClient.configure(x => {
x.withBaseUrl(globalArgs.myBackendUrl);
});
将您的配置字符串注册为模块:
索引.html
<script src="~/Aurelia/jspm_packages/system.js"></script>
<script src="~/Aurelia/config.js"></script>
<script>
// register a module named "my-args" that has a single export: "MyArgs" whose value is whatever the viewbag.MyArgs contains...
System.set('my-args', System.newModule({ MyArgs: '@this.ViewBag.MyArgs' }));
// standard bootstrapping logic...
System.import('aurelia-bootstrapper');
</script>
这里假设剃刀会膨胀{ MyArgs: '@this.ViewBag.MyArgs' }
进入任何@this.ViewBag.MyArgs
返回...例如{ MyArgs: 'debug=true' }
或者其他什么...你必须尝试那个部分。
然后在你的 javascript 代码中你将能够像这样访问参数:
import {MyArgs} from 'my-args';
这是一个正在工作的笨蛋:
http://plnkr.co/edit/Scu8bN?p=preview http://plnkr.co/edit/Scu8bN?p=preview
这是有关的文档System.set
API:
https://github.com/systemjs/systemjs/blob/master/docs/system-api.md#systemsetmodulename-module https://github.com/systemjs/systemjs/blob/master/docs/system-api.md#systemsetmodulename-module
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)