Full crud with the delete

This commit is contained in:
2023-01-18 19:53:58 +01:00
parent ddb3706e44
commit aa4399ea20
3 changed files with 25 additions and 7 deletions

View File

@@ -1,12 +1,12 @@
import {Component, Input, OnInit} from '@angular/core';
import { Component, Input, OnInit } from '@angular/core';
import { FormGroup } from '@angular/forms';
import { FormlyFieldConfig } from '@ngx-formly/core'
import { FormlyJsonschema } from '@ngx-formly/core/json-schema';
import { Router } from '@angular/router';
import { ActivatedRoute, Router } from '@angular/router';
import { CrudService } from '../crud.service'
import {BehaviorSubject} from "rxjs";
import {JsonschemasService} from "../jsonschemas.service";
import { BehaviorSubject } from "rxjs";
import { JsonschemasService } from "../jsonschemas.service";
export interface Model {
email: string;
@@ -35,7 +35,8 @@ export class CardComponent implements OnInit {
constructor(private crudService: CrudService,
private jsonSchemasService: JsonschemasService,
private formlyJsonschema: FormlyJsonschema,
private router: Router
private router: Router,
private route: ActivatedRoute,
) { }
ngOnInit(): void {
@@ -70,6 +71,14 @@ export class CardComponent implements OnInit {
}
}
onDelete() {
this._loading$.next(true);
this.crudService.delete(this.resource!, this.model).subscribe((model: any) => {
this._loading$.next(false);
this.router.navigate(['../'], {relativeTo: this.route});
});
}
isCreateForm() {
return this.resource_id === null;
}