如何将(Debug vs Release)args传递给Asp.Net MVC中的Aurelia应用程序 [英] How to pass (Debug vs Release) args to an Aurelia App within Asp.Net MVC
问题描述
你如何将Debug vs Release参数传递给Aurelia应用程序?
在我的情况下,我在一个MVC应用程序中有Aurelia。我想根据我的web.config值为Aurelia配置一些参数(URL等)。
有没有办法可以达到类似的目的:
< script src =〜/ Aurelia / jspm_packages / system.js>< /脚本>
< script src =〜/ Aurelia / config.js>< / script>
< script>
System.import('aurelia-bootstrapper',@ this.ViewBag.MyArgs);
< / script>
其中 this.ViewBag.MyArgs 会包含从MVC加载的参数吗? / p>
然后我可以在我的Aurelia服务中使用这些args,例如
this.httpClient.configure(x => {
x.withBaseUrl(globalArgs.myBackendUrl);
});
将配置字符串注册为模块:
index.html
< script src =〜/ Aurelia / jspm_packages / system.js>< / script>
< script src =〜/ Aurelia / config.js>< / script>
< script>
//注册一个名为my-args的模块,它只有一个导出:MyArgs,其值是viewbag.MyArgs包含的...
System.set('my-args', System.newModule({MyArgs:'@ this.ViewBag.MyArgs'}));
//标准自举逻辑...
System.import('aurelia-bootstrapper');
< / script>
这里的假设是razor会扩展 {MyArgs:'@ this.ViewBag.MyArgs'}
进入 @ this.ViewBag.MyArgs
返回...例如 {MyArgs:' debug = true'}
或其他......你将不得不玩这个部分。
然后在你的javascript代码,你将能够访问这样的args:
import {MyArgs} from '我-ARGS';
这是一个有效的工作人员:
< a href =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
How would you go about passing Debug vs Release arguments to an Aurelia app?
In my case, I have Aurelia within a MVC app. I would like to configure some parameters (URLs, etc.) for Aurelia depending on my web.config values.
Is there a way I could to something like:
<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 would contains arguments loaded from MVC?
I could then use those args in my Aurelia services such as
this.httpClient.configure(x => {
x.withBaseUrl(globalArgs.myBackendUrl);
});
Register your configuration string as a module:
index.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>
assumption here is that razor will expand { MyArgs: '@this.ViewBag.MyArgs' }
into whatever @this.ViewBag.MyArgs
returns... eg { MyArgs: 'debug=true' }
or something... you'll have to play around with that part.
Then in your javascript code you'll be able to access the args like this:
import {MyArgs} from 'my-args';
Here's a working plunker:
http://plnkr.co/edit/Scu8bN?p=preview
Here's the docs on the System.set
API:
https://github.com/systemjs/systemjs/blob/master/docs/system-api.md#systemsetmodulename-module
这篇关于如何将(Debug vs Release)args传递给Asp.Net MVC中的Aurelia应用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!