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());
}
}
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());
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With