mirror of
https://github.com/akveo/ngx-admin.git
synced 2025-12-16 15:40:11 +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>
|
||||
<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>
|
||||
</nb-card-body>
|
||||
</nb-card>
|
||||
|
|
@ -16,7 +16,7 @@ export class PromotionComponent implements OnInit {
|
|||
addButtonContent: '<i class="nb-plus"></i>',
|
||||
createButtonContent: '<i class="nb-checkmark"></i>',
|
||||
cancelButtonContent: '<i class="nb-close"></i>',
|
||||
createConfirm: true,
|
||||
confirmCreate: true,
|
||||
},
|
||||
edit: {
|
||||
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?')) {
|
||||
event.confirm.resolve();
|
||||
this.service.postPromotion(event.newData).subscribe();
|
||||
event.confirm.resolve(event.newData);
|
||||
} else {
|
||||
event.confirm.reject();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,8 +1,8 @@
|
|||
import {Injectable} from '@angular/core';
|
||||
import {HttpClient} from '@angular/common/http';
|
||||
import {Observable, throwError} from 'rxjs';
|
||||
import {map, catchError} from 'rxjs/operators';
|
||||
import {HttpErrorResponse} from '@angular/common/http';
|
||||
import { Injectable } from '@angular/core';
|
||||
import { HttpClient, HttpHeaders } from '@angular/common/http';
|
||||
import { Observable, throwError } from 'rxjs';
|
||||
import { map, catchError } from 'rxjs/operators';
|
||||
import { HttpErrorResponse } from '@angular/common/http';
|
||||
import { PromotionList } from '../../@core/data/promotion';
|
||||
|
||||
@Injectable({
|
||||
|
|
@ -13,13 +13,26 @@ export class PromotionService {
|
|||
}
|
||||
|
||||
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(
|
||||
map(this.extractData),
|
||||
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[] {
|
||||
return Object.assign(body.promotionList);
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue