우리가 한 일은 외부 모듈 app.config.ts 파일을 모듈 수준에서 포함하고 필요한 곳에 그것을 포함시킵니다. 이것은 파일에있는 내용의 예입니다.
export class Config {
static apiUrl = "api/";
static token = "";
static snackBarDurration = 5000;
......
}
그런 다음 모듈에 선언 한 다음 사용하려는 구성 요소 또는 서비스로 가져 오기 만하면됩니다. 다음은 그 예입니다.
import { Injectable } from "@angular/core";
import { Config } from "../../app.config";
@Injectable()
export class SnackBarService {
.... // declare your snackbar here
constructor() { }
showSnackBar(elementText: string){
let config = new MdSnackBarConfig();
config.duration = Config.snackBarDurration; // Here is your change
this.snackBar.open(elementText, 'OK', config);
}
}