我试图在azure app服务平台(windows机器)上部署一个角度6应用程序.该应用程序本身只是一个新的角度应用程序(从新的appname生成的基本代码).我在本教程后面添加了一些次要代码,以便使用配置文件并在vsts发布管道中利用变量替换 - 管理带有vsts的角度应用程序的设置.
这些是我对生成的应用程序所做的代码更改.在app.module.ts中
export function initializeAppSettings(appSettings: AppSettings) {
return () => appSettings.load();
}
Run Code Online (Sandbox Code Playgroud)
...
providers: [AppSettings, {
provide: APP_INITIALIZER,
useFactory: initializeAppSettings,
deps: [AppSettings],
multi: true
}]
Run Code Online (Sandbox Code Playgroud)
对于我的appsettings.ts文件
export interface AppConfiguration {
apiUrl: string;
}
@Injectable()
export class AppSettings {
static config: AppConfiguration;
constructor(private http: HttpClient) {}
load(): Promise<any> {
const appSettingsJson = environment.production ? 'assets/appsettings.json' : 'assets/appsettings.local.json';
return new Promise<any>(((resolve, reject) => {
this.http.get<AppConfiguration>(appSettingsJson)
.toPromise()
.then(result => {
AppSettings.config = result;
resolve();
}).catch(reason => {
reject(`unable to …Run Code Online (Sandbox Code Playgroud)