2017-03-01 6 views
0

내 angularjs v1 서비스 내에 선언 된이 상수는 webroot입니다.각도 서비스에서 선언 된이 상수 내부 변수 사용

angular.module('myApp.services', []) 
    .value('version', '0.1') 
    .constant('configuration', 
     { 
      webroot: 'http://127.0.0.1:10840' 
     } 
]) 

나는 webroot에서 사용하는 포트 번호에 대한 변수 port 있습니다. 난 port을 사용하여 상수 webroot을 다음과 같은 방식으로 선언하고 싶습니다.

let port = 10840; 

    angular.module('myApp.services', []) 
     .value('version', '0.1') 
     .constant('configuration', 
      { 
       webroot: 'http://127.0.0.1:' + port 
      } 
    ]) 

어떻게 각도 v1에서이 작업을 수행 할 수 있습니까?

+0

http://stackoverflow.com/a/38366461/6449750 –

답변

0

네, 그렇게 할 수 있습니다. 다음은 샘플 데모가

let port = 10840; 
 
angular.module("app",[]) 
 
.value('version', '0.1') 
 
.constant('configuration', 
 
    { 
 
     webroot: 'http://127.0.0.1:' + port 
 
    } 
 
) 
 
.controller("ctrl",function($scope,configuration){ 
 
\t console.log(configuration.webroot) 
 
})
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.0.1/angular.min.js"></script> 
 
<div ng-app="app" ng-controller="ctrl"> 
 

 
</div>