toSignal via Gemini
This commit is contained in:
@@ -1,16 +0,0 @@
|
||||
import { DataSource } from '@angular/cdk/collections';
|
||||
import { Observable, of as observableOf } from 'rxjs';
|
||||
|
||||
import { Role } from '../role';
|
||||
|
||||
export class RoleListDataSource extends DataSource<Role> {
|
||||
constructor(public data: Role[]) {
|
||||
super();
|
||||
}
|
||||
|
||||
connect(): Observable<Role[]> {
|
||||
return observableOf(this.data);
|
||||
}
|
||||
|
||||
disconnect() {}
|
||||
}
|
||||
@@ -5,7 +5,7 @@
|
||||
Add
|
||||
</a>
|
||||
</h2>
|
||||
<mat-table #table [dataSource]="dataSource" aria-label="Elements">
|
||||
<mat-table #table [dataSource]="dataSource()" aria-label="Elements">
|
||||
<!-- Name Column -->
|
||||
<ng-container matColumnDef="name">
|
||||
<mat-header-cell *matHeaderCellDef>Name</mat-header-cell>
|
||||
|
||||
@@ -1,31 +1,22 @@
|
||||
import { Component, OnInit, inject } from '@angular/core';
|
||||
import { Component, inject, computed } from '@angular/core';
|
||||
import { MatButtonModule } from '@angular/material/button';
|
||||
import { MatIconModule } from '@angular/material/icon';
|
||||
import { MatTableModule } from '@angular/material/table';
|
||||
import { ActivatedRoute, RouterLink } from '@angular/router';
|
||||
|
||||
import { Role } from '../role';
|
||||
import { RoleListDataSource } from './role-list-datasource';
|
||||
|
||||
import { RoleService } from '../role.service';
|
||||
@Component({
|
||||
selector: 'app-role-list',
|
||||
templateUrl: './role-list.component.html',
|
||||
styleUrls: ['./role-list.component.css'],
|
||||
imports: [MatButtonModule, MatIconModule, MatTableModule, RouterLink],
|
||||
})
|
||||
export class RoleListComponent implements OnInit {
|
||||
export class RoleListComponent {
|
||||
private roleService = inject(RoleService);
|
||||
private route = inject(ActivatedRoute);
|
||||
listResource = this.roleService.list();
|
||||
|
||||
list: Role[] = [];
|
||||
dataSource: RoleListDataSource = new RoleListDataSource(this.list);
|
||||
dataSource = computed(() => this.listResource.value() ?? []);
|
||||
/** Columns displayed in the table. Columns IDs can be added, removed, or reordered. */
|
||||
displayedColumns = ['name', 'includedRoles', 'permissions'];
|
||||
|
||||
ngOnInit() {
|
||||
this.route.data.subscribe((value) => {
|
||||
const data = value as { list: Role[] };
|
||||
this.list = data.list;
|
||||
});
|
||||
this.dataSource = new RoleListDataSource(this.list);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user