HTTP进入app.module.ts

时间:2018-03-12 07:59:16

标签: angular api typescript

我正在尝试从服务器读取一些凭据并将其添加到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')
    }
}

执行此操作的正确方法是什么?

0 个答案:

没有答案