I have a class like this:
id: any;
phonenumber: PhoneNumberInterface;
httpOptions = {
headers: new HttpHeaders({
'Content-Type': 'application/json',
'Access-Control-Allow-Origin': '*',
'Access-Control-Allow-Methods': 'GET, POST, PUT, DELETE, OPTIONS',
'Access-Control-Allow-Headers': 'Origin, X-Requested-With, Content-Type, Accept, Authorization'
})};
constructor(private route: ActivatedRoute, private httpClient: HttpClient) { }
ngOnInit() {
this.id = this.route.snapshot.paramMap.get('id');
this.getPhoneNumber(this.id).subscribe(phonenumber => this.phonenumber = phonenumber);
}
updatePhoneNumber(phonenumber: PhoneNumberInterface): Observable<any> {
console.log('updatePhoneNumber is called');
phonenumber.phoneNumberType = 'BLOCKED';
console.log(phonenumber);
const url = `http://localhost:8080/phonenumbersmanagement/api/v1/phonenumbers/${this.id}`;
return this.httpClient.put(url, phonenumber, this.httpOptions).pipe();
}
getPhoneNumber(id: number): Observable<PhoneNumberInterface> {
const url = `http://localhost:8080/phonenumbersmanagement/api/v1/phonenumbers/${id}`;
return this.httpClient.get<PhoneNumberInterface>(url).pipe();
}
The update happens when I click on a button:
<button (click)="updatePhoneNumber((phonenumber))">Manuell sperren</button>
The focus lies on updatePhoneNumber().
I am trying to update a phonenumber, which is a big object in my rest application. Before I am using the put()-method, I am print the "phonenumber" variable to the console. It is perfectly fine, but nothing happens. The object doesn't get updated. And I also don't receive any error code. Does anybody know why?
Thank you for every answer!