저는 angi-cli에 익숙하지 않고 env에서 내 API 서비스 호출에 대한 URL을로드하려고합니다. 예 :angular2에 대한 angular-cli 환경 변수를로드하는 방법
local: http://127.0.0.1:5000
dev: http://123.123.123.123:80
prod: https://123.123.123.123:443
export const environment = {
production: true
"API_URL": "prod: https://123.123.123.123:443"
};
그러나 angular2에서
, 내가 그렇게 전화를 어떻게 내가 API_URL를 얻을 수 있습니다 : environment.prod.ts 에 나는이 가정?import { environment } from './environments/environment';
, 당신은 단지이 당신의 API를 URL을 얻으려면 : 당신의 프로젝트를 생성하여 각-CLI의 루트를 보면, 당신은 main.ts에서 볼 수
this.http.post(API_URL + '/auth', body, { headers: contentHeaders })
.subscribe(
response => {
console.log(response.json().access_token);
localStorage.setItem('id_token', response.json().access_token);
this.router.navigate(['/dashboard']);
},
error => {
alert(error.text());
console.log(error.text());
}
);
}
감사
그러나 그런 식으로 보일 수 있습니다 : '../../environments/environment'에서 가져 오기 {환경을}; 개발자 환경에 앱을 하드 코딩해야합니다. prod 환경 파일은 environment.prod.ts입니다. 만약 당신이 'ng build --prod'를한다면, ValuesService는 어떻게 environtment.prod에서 URL을 얻을 수 있습니까? – Pascal
빌드 할 때 지정한 환경에 적합한 환경 파일이 패키지화됩니다. –