I've tried various solutions from different sources but none seem to be resolving the issue I'm facing. The problem is: when trying to run my app, I encounter the following error:
10% building modules 0/1 modules 1 active …\src\app\contacts\contacts.component.tsERROR in src/app/contact.service.ts(18,7): error TS1128: Declaration or statement expected. src/app/contact.service.ts(27,7): error TS1128: Declaration or statement expected. src/app/contact.service.ts(33,7): error TS1128: Declaration or statement expected.
import { Injectable } from '@angular/core';
import { Http, Headers, Response} from '@angular/http';
import { Contact } from './contact';
import 'rxjs/add/operator/map';
import { map } from 'rxjs/operators';
@Injectable({
providedIn: 'root'
})
export class ContactService {
constructor(private http: Http) { }
// Retrieving contacts
getContacts() {
return this.http.get('http://localhost:3000/api/contacts');
.map((res: any) => res.json());
}
// Adding contacts
addContact(newContact) {
var headers = new Headers;
headers.append('Content-Type', 'application/json');
return this.http.post('http://localhost:3000/api/contact', newContact, {headers: headers});
.map((res: Response) => res.json());
}
// Delete contact method
deleteContact(id) {
return this.http.delete('http://localhost:3000/api/contact' + id);
.map((res: Response) => res.json());
}
}
The line containing
.map((res: any) => res.json());
indicates:
declaration or statement expected.