mirror of
https://github.com/akveo/ngx-admin.git
synced 2025-12-18 16:30:13 +01:00
add post method
This commit is contained in:
parent
436db5333b
commit
02368778a4
3 changed files with 24 additions and 10 deletions
|
|
@ -5,7 +5,7 @@
|
||||||
|
|
||||||
<nb-card-body>
|
<nb-card-body>
|
||||||
<ng2-smart-table [settings]="settings" [source]="source" (deleteConfirm)="onDeleteConfirm($event)"
|
<ng2-smart-table [settings]="settings" [source]="source" (deleteConfirm)="onDeleteConfirm($event)"
|
||||||
(userRowSelect)="openWindowForm($event)" (createConfirm)="onCreateConfirm($event)">
|
(createConfirm)="onCreateConfirm($event)" (userRowSelect)="openWindowForm($event)">
|
||||||
</ng2-smart-table>
|
</ng2-smart-table>
|
||||||
</nb-card-body>
|
</nb-card-body>
|
||||||
</nb-card>
|
</nb-card>
|
||||||
|
|
@ -16,7 +16,7 @@ export class PromotionComponent implements OnInit {
|
||||||
addButtonContent: '<i class="nb-plus"></i>',
|
addButtonContent: '<i class="nb-plus"></i>',
|
||||||
createButtonContent: '<i class="nb-checkmark"></i>',
|
createButtonContent: '<i class="nb-checkmark"></i>',
|
||||||
cancelButtonContent: '<i class="nb-close"></i>',
|
cancelButtonContent: '<i class="nb-close"></i>',
|
||||||
createConfirm: true,
|
confirmCreate: true,
|
||||||
},
|
},
|
||||||
edit: {
|
edit: {
|
||||||
editButtonContent: '<i class="nb-edit"></i>',
|
editButtonContent: '<i class="nb-edit"></i>',
|
||||||
|
|
@ -59,9 +59,10 @@ export class PromotionComponent implements OnInit {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
onCreateConfirm(event): void {
|
onCreateConfirm(event) {
|
||||||
if (window.confirm('Are you sure you want to save?')) {
|
if (window.confirm('Are you sure you want to save?')) {
|
||||||
event.confirm.resolve();
|
this.service.postPromotion(event.newData).subscribe();
|
||||||
|
event.confirm.resolve(event.newData);
|
||||||
} else {
|
} else {
|
||||||
event.confirm.reject();
|
event.confirm.reject();
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,5 @@
|
||||||
import { Injectable } from '@angular/core';
|
import { Injectable } from '@angular/core';
|
||||||
import {HttpClient} from '@angular/common/http';
|
import { HttpClient, HttpHeaders } from '@angular/common/http';
|
||||||
import { Observable, throwError } from 'rxjs';
|
import { Observable, throwError } from 'rxjs';
|
||||||
import { map, catchError } from 'rxjs/operators';
|
import { map, catchError } from 'rxjs/operators';
|
||||||
import { HttpErrorResponse } from '@angular/common/http';
|
import { HttpErrorResponse } from '@angular/common/http';
|
||||||
|
|
@ -13,13 +13,26 @@ export class PromotionService {
|
||||||
}
|
}
|
||||||
|
|
||||||
getPromotion(): Observable<any> {
|
getPromotion(): Observable<any> {
|
||||||
const url = 'http://34.87.6.140:8011/api/promotions/all';
|
const url = 'http://localhost:8011/api/promotions/all';
|
||||||
return this.http.get(url).pipe(
|
return this.http.get(url).pipe(
|
||||||
map(this.extractData),
|
map(this.extractData),
|
||||||
catchError(this.handleError),
|
catchError(this.handleError),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
postPromotion(data: PromotionList): Observable<any> {
|
||||||
|
console.log(JSON.stringify(data));
|
||||||
|
let headers = new HttpHeaders({
|
||||||
|
'Content-Type': 'application/json',
|
||||||
|
'X-Requested-Method': 'POST',
|
||||||
|
});
|
||||||
|
let options = { headers: headers };
|
||||||
|
const url = 'http://localhost:8011/api/promotions/add';
|
||||||
|
return this.http.post(url, JSON.stringify(data), options).pipe(
|
||||||
|
catchError(this.handleError),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
private extractData(body: any): PromotionList[] {
|
private extractData(body: any): PromotionList[] {
|
||||||
return Object.assign(body.promotionList);
|
return Object.assign(body.promotionList);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue