あなたは、サーバー側のコードでconfigセクションを読み、$http.get
経由で取得することができます。それが最善の解決策です。
MVC ApiControllerにメソッドを書き込む必要があります(MVC Action
でも構いません)。
[Route("settings/{key}")]
[HttpGet]
public HttpResponseMessage GetSetting(string key)
{
try
{
return Request.CreateResponse(HttpStatusCode.OK,
System.Configuration.ConfigurationManager.AppSettings[key]);
}
catch (Exception ex)
{
return Request.CreateErrorResponse(HttpStatusCode.BadRequest, ex)
}
}
そして、あなたの角度のサービスで:ような何か
app.service('utilsService', utilsService);
utilsServcie.$inject = ['$http'];
function utilsServcie($http){
this.readServerProperty = function(key){
$http.get('/api/v1/settings/' + key).then(
function(response){
return response.data;
},
function(error){
alert(error.data.message);
}
);
}
}
そして、あなたはこのように、必要な場所でこのサービスを使用することができます。
app.controller('MainController', MainController);
MainController.$inject = ['utilsServcie'];
function MainController(utilsServcie){
var vm = this;
utilsServcie.readServerProperty('SampleTemplate').then(function(path){
vm.path = path;
});
}
そして、あなたのビューで:
<div ng-controller="MainController as mc">
<a ng-href= "mc.path"> Edit Template</a>
</div>
まあ、私は、これはメモリからのものです。エラーはほとんどありませんが、そのアイデアをキャッチすることができます。
これはすべての人々です。 :D
サーバから設定キーを取得するために '$ http'を使用してajax呼び出しを行い、' $ scope'変数に応答値を割り当てます。 –