Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angularjs/23.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Angularjs 角度权限:测试用户是否具有来自控制器的角色或权限_Angularjs_Angular Permission - Fatal编程技术网

Angularjs 角度权限:测试用户是否具有来自控制器的角色或权限

Angularjs 角度权限:测试用户是否具有来自控制器的角色或权限,angularjs,angular-permission,Angularjs,Angular Permission,我已根据文档在应用程序中定义了我的用户角色和权限 有了它,我可以使用ui指令或ui路由器处理 问:如何测试用户在控制器或服务中是否具有角色或权限 (function() { 'use strict'; angular .module('app') .component('userDetail', component()); /** @ngInject */ function component() { return { restrict

我已根据文档在应用程序中定义了我的用户角色和权限

有了它,我可以使用ui指令或ui路由器处理


问:如何测试用户在控制器或服务中是否具有角色或权限

(function() {
  'use strict';

  angular
    .module('app')
    .component('userDetail', component());

  /** @ngInject */
  function component() {
    return {
      restrict: 'E',
      bindings: {
        user: '<'
      },
      templateUrl: 'app/components/users/user-detail/user-detail.html',
      transclude: true,
      controller: Controller
    }
  }

  /** @ngInject */
  function Controller($log) {
    var ctrl = this;
    ctrl.$onInit = function() {
      $log.log('How to test for user permission?')
      // Something like...
      // if(PermPermission.hasPermission('createUser')) {
      // do something
      // }
    };
  }
})();
(函数(){
"严格使用",;
有棱角的
.module('应用程序')
.component('userDetail',component());
/**@ngInject*/
函数组件(){
返回{
限制:'E',
绑定:{

用户:“@blowsie我就是这样处理的,但感觉很沉重:

导出默认值{
模板:“”,
控制器:类测试{
/*@ngInject*/
构造函数(PermPermissionStore){
PermPermissionStore.definePermission('truePermission',()=>true);
PermPermissionStore.definePermission('falsePermission',()=>false);
const truePerm=PermPermissionStore.getPermissionDefinition('truePermission');
const falsePerm=PermPermissionStore.getPermissionDefinition('falsePermission');
truePerm.validatePermission()
.然后((res)=>{/*你去那里*/})
.catch((e)=>{/*永远不要去那里*/});
falsePerm.validatePermission()
.然后((res)=>{/*永远不要去那里*/})
.catch((e)=>{/*你去那里*/});
}
},

} /代码>请考虑提供一个如果可能的话,或至少张贴你已经尝试过的(代码)/你想要做的(更具体)。这太宽泛了。IMO@AsielLealCeldeiro,在这种情况下,我不同意。这是根据演示