i try to connect my app to an Api using the promises. the update method work's fine but the update one did't work. here it is :
import { Injectable } from '@angular/core';
import { Http, Response } from '@angular/http';
import 'rxjs/add/operator/toPromise';
@Injectable()
export class Croissants {
text: string;
ownerId: number[];
startDate: Date;
endDate: Date;
}
export class Personnes {
text: string;
id: number;
color: string;
}
export class EventService {
constructor(private http: Http) {}
getCroissants() {
return this.http.get('http://localhost:8080/v0/croissants')
.toPromise()
.then(res => <any[]> res.json().data)
.then(data => { return data; });
}
updateCroissants(ownerId, startDate, endDate, text) {
return this.http.put('http://localhost:8080/v0/croissant' + ownerId + startDate + endDate + text)
.toPromise()
.then(res => <any[]> res.json().data)
.then(data => { return data; });
}
deleteCroissants(ownerId) {
return this.http.delete('http://localhost:8080/v0/croissant' + ownerId)
.toPromise()
.then(res => <any[]> res.json().data)
.then(data => { return data; });
}
getPersonnes() {
return this.http.get('http://localhost:8080/v0/persons')
.toPromise()
.then(res => <any[]> res.json().data)
.then(data => { return data; });
}
}
On the update it says : " Supplied parameters do not match any signature of call target "
for further help i give the component :
import { NgModule, Component, enableProdMode } from '@angular/core';
import {BrowserModule} from '@angular/platform-browser';
import {platformBrowserDynamic} from '@angular/platform-browser-dynamic';
import {Croissants, Personnes, Service} from './calendrier.service';
import {DxSchedulerModule, DxCheckBoxModule, DxSelectBoxModule} from 'devextreme-angular';
if(!/localhost/.test(document.location.host)) {
enableProdMode();
}
@Component({
selector: 'calendrier',
templateUrl: './calendrier.component.html',
styleUrls: ['./calendrier.component.css'],
providers: [Service]
})
export class CalendrierComponent {
CroissantsData: Croissants[];
currentDate: Date = new Date(2015, 4, 25);
PersonnesData: Personnes[];
switchModeNames: string[];
constructor(service: Service) {
this.switchModeNames = ["Tabs", "Drop-Down Menu"];
this.CroissantsData = service.getCroissants();
this.PersonnesData = service.getPersonnes();
console.log(this.CroissantsData);
}
}
@NgModule({
imports: [
BrowserModule,
DxSchedulerModule,
DxCheckBoxModule,
DxSelectBoxModule
],
declarations: [CalendrierComponent],
bootstrap: [CalendrierComponent]
})
export class CalendrierModule {}
platformBrowserDynamic().bootstrapModule(CalendrierModule)
all my code is available on my github if you want to keep an eye on it :
Thanks very very much for help
this.http.put('http://localhost:8080/v0/croissants+'id,'')
what is this? What should it look like if id is defined? Something likehttp://localhost:8080/v0/croissants/1
? – eko Jul 11 '17 at 15:51return this.http.put('http://localhost:8080/v0/croissants/'+id)
but where do you provide the id? – eko Jul 11 '17 at 15:58http://localhost:8080/v0/croissant1234
in theupdateCroissants
method. There are no/
s in your code. Can you also share how you call this method? – eko Jul 11 '17 at 16:33