Kim Vu
Kim Vu

Reputation: 668

Angular2, Property 'map' does not exist on type 'Observable'

The imports:

import { Component,OnInit } from '@angular/core';
import { FormGroup, FormControl, Validators, FormBuilder } from '@angular/forms';
import { Application } from './Application';
import { Http, Response } from '@angular/http';
import { NgModule } from '@angular/core'; 
import { Headers } from '@angular/http';
import 'rxjs/add/operator/map';
import 'rxjs/Rx';

The Method:

 saveApplcation() {
    var application = new Application();
    application.ssnr = this.form.value.ssnr;
    application.loanamount = this.form.value.amount;
    application.email = this.form.value.email;
    application.phonenumber = this.form.value.phonenumber;
    application.repaymenttime = this.form.value.time;

    var body: string = JSON.stringify(application);
    var headers = new Headers({ "Content-Type": "application/json" });

    this._http.post("api/Application/", body, { headers: headers })
        .map(returnData => returnData.toString())
        .subscribe(
        retur => {
            this.showForm = false;
            this.showMenu = true;
        },
        error => alert(error),
        () => console.log("done post-api/loan")
        );

};

The error says: TS2339 Property 'map' does not exist on type 'Observable'. TypeScript Virtual Projects C:\Users\kim\Documents\Visual Studio 2015\Projects\NewOblig3\NewOblig3\app\app.component.ts 52 Active

I've seen People import 'rxjs/add/operator/map'; and says it'll work, but not in my case.

Upvotes: 0

Views: 4250

Answers (2)

VeganHunter
VeganHunter

Reputation: 5974

You are using Visual Studio. I had the same issue there.

I solved it by installing TypeScript for Visual Studio 2015

It also fixed IntelliSense for Observable.

Upvotes: 4

dmcblue
dmcblue

Reputation: 363

I've been having the same problem after upgrading from an earlier beta. My issue (and I suspect yours) was in the configuration files package.json and systemjs.config.js. Honestly, I'm not 100% sure what the exact lines that fixed the problem but the format of systemjs.config.js in particular is quite different.

My recommended solution is use these two configuration files from the Quick Start Tutorial to replace your own then run npm install.

After I updated these, I did not need the import 'rxjs/add/operator/map'; fix; everything worked correctly.

Note: You should backup these files before making these changes to make sure you don't lose customizations, and there will probably other issues caused by the upgrades.

Upvotes: 1

Related Questions