我正在尝试设计一个网站。用户可以拥有不同的角色,例如管理员,经理或员工,这些角色将在登录时决定。其余的URL返回登录用户的类型。我想根据用户的类型动态加载视图。动态地我的意思是侧栏必须加载特定于该用户的菜单,并且登陆页面必须是动态的,具体取决于用户。请建议我如何操作或请将我重定向到适当的资源。因为这是我没有的起点要附加的任何代码示例。请帮助。提前感谢。
更新
到目前为止,有一个登录组件会像这样重定向到我的主页
this.router.navigate(['/home']);

,主页菜单从数据库加载,如
this.menuLoader.getFunctionalities(this.empId).subscribe(response => {
this.roleArray=response;
this.roleArray.forEach((element) => {
this.funtionalities = element.functionList;
console.log(element.functionList);
});
});//subscribe ends here
}

并在html中我有
<li *ngFor = "let x of funtionalities" (click)="closeSidenav()"> <a class="item white" [routerLink] = "'/home'+x.FunctionValue">{{ x.FunctionName.toUpperCase() }}</a></li>
&#13;
我有像
这样的数据库结构
{
"_id" : ObjectId("59676398506d3c2e58feb5d2"),
"role" : "admin",
"functionList" : [
{
"FunctionName" : "Create CFT",
"FunctionValue" : "/createCFT"
},
{
"FunctionName" : "Update CFT",
"FunctionValue" : "/updateCFT"
},
{
"FunctionName" : "Add Employee",
"FunctionValue" : "/addEmployee"
},
{
"FunctionName" : "Add Resource",
"FunctionValue" : "/addResource"
},
{
"FunctionName" : "Add Employees-Excel",
"FunctionValue" : "/addEmployeesExcel"
},
{
"FunctionName" : "Add Holiday List",
"FunctionValue" : "/holidayList"
},
{
"FunctionName" : "Add Employees to CFT",
"FunctionValue" : "/addEmployeeToCft"
}
]
}
&#13;
答案 0 :(得分:0)
您的媒体资源functionList
包含未在*ngFor
修改中使用的路由内容,如下所示
<li *ngFor = "let x of funtionalities.functionList" (click)="closeSidenav()">
<a class="item white" [routerLink] = "'/home'+x.FunctionValue">
{{ x.FunctionName.toUpperCase() }}
</a>
</li>