Reputation: 31
I'm following a tutorial on how to build a MEAN stack from this link: https://www.youtube.com/watch?v=wtIvu085uU0, however I'm stuck on creating the angular part around 59:34. The tutorial is using angular2 while I'm using angular6. The main part that's holding me up is contact.service.ts, and getting the addContacts, getContacts, and deleteContact methods to work, as the .map method has changed since angular 2. I changed his code from:
getContacts() {
return this.http.get('http://localhost:3000/api/contacts')
.map(res => res.json());
}
which returned "Property 'map' does not exist on type 'Observable'" error to
getContacts() {
return this.http.get('http://localhost:3000/api/contacts')
.pipe(
.map(res => res.json())
);
}
which now returns "ERROR in src/app/contact.service.ts(17,7): error TS1135: Argument expression expected." in the console I think I've gotten over the map error but I don't know what the Argument expression expected error means. The other two methods had the same problem, before and after changing map to pipe. As it is now, it won't compile and display the "contacts works" page shown in the video at 1:03:37. The console shows no other errors in other classes, so I think this is the only error.
Upvotes: 3
Views: 21982
Reputation: 145950
I'm sure you can get this error for many reasons, but if you use a reserved word as a variable in some contexts you may not get a better error. For instance var
is a reserved keyword so this is invalid.
// Argument expression expected.
variables.forEach(var => {
});
Whereas if you had done the following you'd get a more useful error.
// 'var' is not allowed as a variable declaration name
const var = 456;
Upvotes: 0
Reputation: 1976
Whatever Sean said plus you have to import the map
operator :
import {map} from 'rxjs/operators';
at the beginning of the file
Upvotes: 0
Reputation: 120644
After reformatting your code, the answer is obvious. You have an errant .
before your call to map()
:
getContacts() {
return this.http.get('http://localhost:3000/api/contacts')
.pipe(
.map(res => res.json())
// ^ remove this period
);
}
Upvotes: 11