---
order: 2
title: AcService
type: Documents
---

`AcService` 提供了众多 API 便于通过编程的方式去控制访问

```typescript
import { BixiACService } from '@bixi/ac';

@Component({})
export class AppListComponent implements OnInit {
  constructor(private acService: BixiACService) {}

  onDelete() {
    if (!this.acService.ac(['app.delete'])) {
      alert('没有删除的权限');
      return;
    }
  }
}
```

### API

| 方法 | 描述 |
| --- | ---- |
|`setPermissions(permissions: string | string[]) => void` | 设置权限列表 |
|`setRoles(roles: string | string[]) => void`             | 设置角色列表 |
|`getPermissions:() => string[]`                          | 获取权限列表 |
|`getRoles() => string[]`                                 | 获取角色列表 |
|`ac(data: string| string[], { isRole: boolean }) => boolean`        | 拥有所有 |
|`acAny(data: string| string[], { isRole: boolean }) => boolean`     | 拥有任意一个 |
|`ace(data: string| string[], { isRole: boolean }) => boolean`       | 所有都缺失 |
|`aceAny(data: string| string[], { isRole: boolean }) => boolean`    | 缺失任意一个 |


