0

I'm trying to migrate a project from Angular2 beta1 to Angular2 beta15 and I have some issues.

I have error message : 'map' property does not exists on 'Observable< Response >'

Example of code with this error :

import { Injectable } from 'angular2/core';
import { Http, Response, Headers } from 'angular2/http';
import { Observable } from 'rxjs/Observable';
import { HelperModule } from './helpers.module';
import { BlogPost } from './model';
import 'rxjs/add/operator/map';

/**
 * Service dealing with blog data
 */
@Injectable()
export class DataService {

    constructor(private http: Http) { }

    /**
     * Call API to list available blog posts
     */
    listBlogPosts() {
        return this.http.get(HelperModule.UrlBuilder.BuildPostListUrl()).map(res => (<Response>res).json());
    }

}

Code is available here : https://github.com/AdrienTorris/AspNet5Angular2Playground

EDIT : I'm using rxjs 5.0.0-beta6 and typescript 1.8.10, targetting es6

AdrienTorris
  • 9,111
  • 9
  • 34
  • 52

2 Answers2

1

Try using the latest version of Typescript (1.9) to compile your code. Module augmentation is bugged in some minor versions of TS 1.8. RXJS changed the way it defines its modules after 5.0.0-beta2.

You can try the nightly build using: npm install -g typescript@next

Jean-Philippe Leclerc
  • 6,713
  • 5
  • 43
  • 66
0

You need to import the map operator:

import 'rxjs/add/operator/map';

or all operators:

import 'rxjs/Rx';

See this question:

Community
  • 1
  • 1
Thierry Templier
  • 198,364
  • 44
  • 396
  • 360
  • map operator is imported. I test with import all. – AdrienTorris Apr 19 '16 at 09:55
  • Mum. Is the same when using `import 'rxjs/Rx';`? I created a plunkr with beta15 and it works for me: https://plnkr.co/edit/7Psl5Q0DGFLxlb4DH0lO?p=preview. I get rxjs from code.angularjs.org so I don't exactly know the version. I guess that it's rxjs beta2 as described in https://angular.io/docs/ts/latest/quickstart.html. Do you have the same error when using this version with angular2 beta15? – Thierry Templier Apr 19 '16 at 12:47
  • with rxjs 5.0.0-beta2 it works, but I have some other problems with the migration. – AdrienTorris Apr 19 '16 at 13:40
  • Okay great! Which problems? – Thierry Templier Apr 19 '16 at 13:41
  • Error Token must be defined! at Function.Injector.resolve (http://localhost:48900/js/angular2/angular2.dev.js:11152:25) at Injector.resolveAndCreateChild (http://localhost:48900/js/angular2/angular2.dev.js:11198:40) at http://localhost:48900/js/angular2/angular2.dev.js:12529:42 – AdrienTorris Apr 19 '16 at 13:46
  • Are you targeting es5 or es6 ? – AdrienTorris Apr 19 '16 at 13:46
  • Do you know which token isn't defined? – Thierry Templier Apr 19 '16 at 13:47
  • with es5 I have so many errors ...like 'Map is undefined' or 'Iterator is undefined'. With es6 solution builds. For the token I don't know, I don't use token in the application and all worked before the migration – AdrienTorris Apr 19 '16 at 13:52
  • Do you add the polyfills files? – Thierry Templier Apr 19 '16 at 13:56
  • For the token, perhaps you could enable "pause on exceptions" in dev tools (Sources tab). This way, you will be able to debug this... – Thierry Templier Apr 19 '16 at 13:57
  • Yes I add polyfills file, this is my gulp task for angular: var angularJs = [ './node_modules/angular2/bundles/angular2.dev.js', './node_modules/angular2/bundles/router.dev.js', './node_modules/angular2/bundles/angular2-polyfills.js', './node_modules/angular2/bundles/http.dev.js' ]; – AdrienTorris Apr 19 '16 at 13:58