0
私は、更新していないjsonを初めて更新するボタンをクリックします。何もJSONに起こりませんが、私はそれをクリックした場合は、再度、それは私が(disputa.propostas_realizadas
)サーバを更新するために2回クリックする必要があります - Angular2
recusaProposta(){
this.propostaService.atualizaDisputa(this.disputa)
.subscribe(
res => this.disputa.propostas_realizadas++,
error => console.log(error)
);
}
:問題のボタンは、この関数を呼び出します
サービスは
import {Injectable} from '@angular/core';
import {Http, Headers, Response, RequestOptions} from '@angular/http';
import {Component} from '@angular/core';
import {Observable} from 'rxjs/Rx';
import {DisputaPropostaComponent} from './disputas-proposta.component';
import 'rxjs/add/operator/map';
@Injectable()
export class DisputaPropostaService{
contato:Object[] = [];
name: string;
headers:Headers;
url: string = 'http://localhost:3004/disputa';
constructor(private http: Http){}
atualizaDisputa (body:any): Observable<DisputaPropostaComponent[]>{
let bodyString = JSON.stringify(body); // Stringify payload
let headers = new Headers({ 'Content-Type': 'application/json' }); // ... Set content type to JSON
let options = new RequestOptions({ headers: headers }); // Create a request option
return this.http.put(`${this.url}/${body['id']}`, body, options) // ...using post request
.map((res:Response) => res.json()) // ...and calling .json() on the response to return data
.catch((error:any) => Observable.throw(error.json().error || 'Ocorreu um erro em nosso servidor, tente novamente mais tarde')); //...errors if any
}
}
私はお手伝いできますか?前もって感謝します。
答えに感謝し、それはまだ私が初めてで 'disputa.propostas_realizadas'と、このアップデートを印刷するように求めているが、JSONが更新されていないボタンをクリックした直後に、:(機能しません。 :(でも、とにかくありがとう –