Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Angular 6 error TS1135: Argument expression expected

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.

like image 209
mtangmt Avatar asked Jan 21 '26 14:01

mtangmt


1 Answers

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
        );
}

Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!