Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Problems with .maps and import 'rxjs/add/operator/map';

Tags:

angular

rxjs

I've got a problem with Angular 4 and rxjs/add/operator/map. Although I import rxjs/add/operator/map into my file, I can't use .map. Visual Basics always shows two messages:

message: 'Declaration or statement expected.'

message: 'Cannot find name 'map'. Did you mean 'Map'?'

I have tried some things people advised on here and on the internet like: '

npm install rxjs@latest --save

I have also tried to update everything with

npm update

But this problem does not want to go away.

Here is the context for my code. I'm very new to programming and this is a part of a tutorial:

import { Injectable } from '@angular/core';
import { Http } from '@angular/http';
//import { Observable } from 'rxjs/Observable';
import 'rxjs/add/operator/map';

@Injectable()
export class DataService {

  constructor(public http:Http) { 
    console.log('Data service connected...');
  }

  getPosts(){
    this.http.get('https://jsonplaceholder.typicode.com/posts');
      .map(res => res.json());
  }

}
like image 690
Helmut K. Avatar asked Dec 11 '25 17:12

Helmut K.


1 Answers

I guess the issue is semicolon after this.http.get method

import { Injectable } from '@angular/core';
import { Http } from '@angular/http';
//import { Observable } from 'rxjs/Observable';
import 'rxjs/add/operator/map';

@Injectable()
export class DataService {

  constructor(public http:Http) { 
    console.log('Data service connected...');
  }

 getPosts(){
   this.http.get('https://jsonplaceholder.typicode.com/posts') 
    .map(res => res.json());
 }

}
like image 167
user1608841 Avatar answered Dec 13 '25 08:12

user1608841



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!