당신은 서버 측 코드에서 설정 섹션을 읽고 $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'를 사용하여 서버에서 구성 키를 가져오고'$ scope' 변수에 응답 값을 지정하여 ajax를 호출하십시오. –