【发布时间】:2017-12-31 17:22:56
【问题描述】:
由于我是 angular 2/4 新手,我无法根据需要设置新应用程序。
我正在尝试构建一个将从其他应用程序调用的应用程序。调用应用程序将发送一些参数,如令牌、用户名、应用程序 ID 等。
现在,就像在 Angular 2/4 中一样,app.component 是我们的登陆组件,每个第一个请求都将通过它。所以,我想在应用程序组件中获取这些参数并加载一些用户详细信息,进行本地会话并转移到其他内容。
问题是当我尝试访问这些参数时,我得到了任何东西。
这是启动我的 Angular 应用程序的 URL: http://localhost:86/dashboard?username=admin&token=xyz&appId=8
这是我的路由文件代码:
const routes: Routes = [
{
path: 'dashboard/:username, token', component: AppComponent
}
];
@NgModule({
imports: [RouterModule.forRoot(routes)],
exports: [RouterModule]
})
export class AppRoutingModule {
}
这是我的应用组件代码:
import { Component, OnInit } from '@angular/core';
import { AuthenticationService } from 'app/services/authentication/authentication.service';
import { User } from 'app/models/user/user';
import { AppConfig } from 'app/helpers/AppConfig';
import { ActivatedRoute, Router } from '@angular/router';
@Component({
selector: 'app-root',
templateUrl: './app.component.html',
styleUrls: ['./app.component.css']
})
export class AppComponent implements OnInit {
_user: User = new User();
obj: any;
error: any;
loginName: string;
private id: any;
constructor(
private authenticationService: AuthenticationService,
private config: AppConfig,
private route: ActivatedRoute,
private router: Router
) { }
ngOnInit() {
this.loadCurrentUserDetail();
this.getParamValues()
}
getParamValues() {
this.id = this.route.queryParams.subscribe(params => {
this.loginName = params['username'];
});
}
这里的参数是空的不知道为什么?
提前致谢!
在图像参数对象中什么都没有。
【问题讨论】: