答案 0 :(得分:0)
如果您希望数据在会话中保持不变,则可以使用浏览器的LocalStorage
API。
添加项目
this.permissions = JSON.parse(window.localStorage.getItem("permissions"));
要检索它,
window.localStorage.removeItem("permissions");
要删除项目,
song
您可以在Chrome开发者工具中检查localStorage项目,在应用程序>存储>本地存储
下注意:如果未启用Cookie,此方法将失败。
PS:我不建议在LocalStorage中存储权限,最好从API调用中获取它们。
答案 1 :(得分:0)
在AppModule中添加请求以在每次刷新后检索权限
import { Component, OnInit } from '@angular/core';
import { NgxPermissionsService } from 'ngx-permissions';
import { HttpClient } from '@angular/common/http';
@Component({
selector: 'app-root',
templateUrl: './app.component.html',
styleUrls: ['./app.component.css']
})
export class AppComponent implements OnInit {
title = 'app';
constructor(private permissionsService: NgxPermissionsService,
private http: HttpClient) {}
ngOnInit(): void {
const perm = ["ADMIN", "EDITOR"];
this.permissionsService.loadPermissions(perm);
this.http.get('url').subscribe((permissions) => {
//const perm = ["ADMIN", "EDITOR"]; example of permissions
this.permissionsService.loadPermissions(permissions);
})
}
}