Full crud with the C
This commit is contained in:
@@ -2,9 +2,9 @@ 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 { CrudService } from '../crud.service'
|
||||
import {ParamMap} from "@angular/router";
|
||||
import {BehaviorSubject} from "rxjs";
|
||||
|
||||
export interface Model {
|
||||
@@ -32,11 +32,9 @@ export class CardComponent implements OnInit {
|
||||
}
|
||||
|
||||
constructor(private crudService: CrudService,
|
||||
private formlyJsonschema: FormlyJsonschema
|
||||
) {
|
||||
|
||||
|
||||
}
|
||||
private formlyJsonschema: FormlyJsonschema,
|
||||
private router: Router
|
||||
) { }
|
||||
|
||||
ngOnInit(): void {
|
||||
this._loading$.next(true);
|
||||
@@ -54,7 +52,7 @@ export class CardComponent implements OnInit {
|
||||
if (this.resource_id !== null) {
|
||||
this.crudService.get(this.resource_id!).subscribe((model: any) => {
|
||||
this.model = model
|
||||
})
|
||||
});
|
||||
|
||||
this._loading$.next(false);
|
||||
}
|
||||
@@ -62,10 +60,17 @@ export class CardComponent implements OnInit {
|
||||
|
||||
onSubmit(model: any) {
|
||||
this._loading$.next(true);
|
||||
this.crudService.update(model).subscribe((model: any) => {
|
||||
this.model = model
|
||||
this._loading$.next(false);
|
||||
})
|
||||
if (this.resource_id !== null) {
|
||||
this.crudService.update(model).subscribe((model: any) => {
|
||||
this.model = model;
|
||||
this._loading$.next(false);
|
||||
});
|
||||
} else {
|
||||
this.crudService.create(model).subscribe((response: any) => {
|
||||
this._loading$.next(false);
|
||||
this.router.navigateByUrl('/entities/' + response.id);
|
||||
});
|
||||
}
|
||||
console.log(model);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -35,4 +35,11 @@ export class CrudService {
|
||||
model
|
||||
);
|
||||
}
|
||||
|
||||
public create(model: any) {
|
||||
return this.http.post<{ menu: [{}] }>(
|
||||
`/api/v1/entity/`,
|
||||
model
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user