我正在尝试从服务器读取一些凭据并将其添加到app.module.ts
const appRoutes: Routes = [
{ path: 'operation-log', component: OperationLogComponent },
{ path: 'person-concepts', component: frmPersonBegrepp },
{ path: 'payslip-setup', component: LönespecifikationComponent },
{ path: '', redirectTo: '/payslip-setup'+getCredentials(), pathMatch: 'full' }
];
我不知道如何实施getCredentials()
。我没有constructor
来发起HttpClient
。我设法创建了这样的函数,但它返回Observable
function getCredentials() {
if (!environment.production) {
return (new HttpClient(HttpHandler.prototype)).get('http://localhost:3000')
}
}
执行此操作的正确方法是什么?