是否可以根据用户角色切换角度类似切换模板的组件?:
@Component({
selector: 'app-order-select',
template: `
<div *ngIf="storage.getUserRole() == 'admin'">{require('./order-select.component.html')} </div>
<div *ngIf="storage.getUserRole() == 'legal'"> {require('./order-select.component-legal.html')} </div>`,
styleUrls: ['./order-select.component.css']
})
export class OrderSelectComponent implements OnInit {
}
我的应用路线:
{
path: 'orders/select',
component: OrderSelectComponent,
canActivate: [AuthGuard]
},
答案 0 :(得分:1)
您可以使用:
<div id="roleDependantContent">
<app-component-admin *ng-if="storage.getUserRole() == 'admin'"/>
<app-component-user *ng-if="storage.getUserRole() == 'user'"/>
</div>
它只会加载适合您用户角色的组件。