Please provide us with the following information:
Windows 7, 8 or 10. Linux (which distribution). Mac OSX (Yosemite? El Capitan?)
Windows 7
Please run
ng --version. If there's nothing outputted, please run in a Terminal:node --versionand paste the result here:
1.0.0-beta.21
Was this an app that wasn't created using the CLI? What change did you do on your code? etc.
- CLI: ng new ngcli_demo_b21
- CLI: ng g service srv
- in the srv.service.ts file add: import {Http} from '@angular/http';
- in the srv.service.ts file replace the constructor with::
constructor(http: Http) {
return http.get('/dummy-data/items.json').map(res => res.json());
}- in the srv.service.spec.ts file add: import {HttpModule} from '@angular/http';
- edit: srv.service.spec.ts - add HttpModule in beforeEach:
- CLI: ng test
Normally this include a stack trace and some more information.
Stack trace (location has been removed for security reasons):
ERROR in [default]
Property 'map' does not exist on type 'Observable
23 11 2016 13:13:59.584:WARN [karma]: Port 9876 in use
23 11 2016 13:13:59.586:INFO [karma]: Karma v1.2.0 server started at http://localhost:9877/
23 11 2016 13:13:59.587:INFO [launcher]: Launching browser Chrome with unlimited concurrency
23 11 2016 13:13:59.664:INFO [launcher]: Starting browser Chrome
23 11 2016 13:14:01.025:INFO [Chrome 54.0.2840 (Windows 7 0.0.0)]: Connected on socket /#vSWl35wXjIdlsGcgAAAA with id 6986885
Chrome 54.0.2840 (Windows 7 0.0.0) SrvService should ... FAILED
TypeError: http.get(...).map is not a function
at new SrvService (webpack:
at DynamicTestModuleInjector.get (/DynamicTestModule/module.ngfactory.js:150:65)
at DynamicTestModuleInjector.getInternal (/DynamicTestModule/module.ngfactory.js:215:50)
at DynamicTestModuleInjector.NgModuleInjector.get (webpack:
at TestBed.get (webpack:
at webpack:
at Array.map (native)
at TestBed.execute (webpack:
at Object.
at ZoneDelegate.invoke (webpack:
at ProxyZoneSpec.onInvoke (webpack:
Chrome 54.0.2840 (Windows 7 0.0.0): Executed 4 of 4 (1 FAILED) (0.287 secs / 0.194 secs)
note that:
This issue can be solved by adding the following code to srv.service.ts
import 'rxjs/Rx';
OR
import {Observable} from 'rxjs';
import 'rxjs/add/operator/map';
HOWEVER
this required for tests only, as ng serve works just fine without it
Thanks! We'll be in touch soon.
This has to do with how rxjs works. Basically you need to import the operators before using them. This is overall fine in your app, but in your tests you also have to do that, because they only import the specific components and will not import the whole app.
@filipesilva but test bundle imports polyfills file which in the same time imports everything from rxjs
@filipesilva just upgraded to 1.0.0, it's complaining in the service that Property 'map' does not exist on type 'Observable
import { Injectable } from '@angular/core';
import { Http } from '@angular/http';
import { Observable } from 'rxjs/observable';
import 'rxjs/add/operator/map'
@Injectable()
export class CommonService {
constructor(private http: Http) { }
httpGet(url) {
return this.http.get(url)
.map(response => response.json());
}
}
I solved issue by adding following includes in test.ts file in src/app folder in my solution
import 'core-js/es6';
import 'core-js/es7/reflect';
import 'ts-helpers';
import 'zone.js/dist/zone.js';
import 'zone.js/dist/long-stack-trace-zone';
import 'zone.js/dist/proxy.js';
import 'zone.js/dist/sync-test';
import 'zone.js/dist/jasmine-patch';
import 'zone.js/dist/async-test';
import 'zone.js/dist/fake-async-test';
import { getTestBed } from '@angular/core/testing';
import {
BrowserDynamicTestingModule,
platformBrowserDynamicTesting
} from '@angular/platform-browser-dynamic/testing';
import 'rxjs/Rx';
adding specific operators or extensions in component/service/etc. ts file do not make any difference.
import map like this : import { map } from "rxjs/operators";
and then use map like this
pipe(map(res => res.json()));
so
map(res=>res.json()) becomes pipe(map(res => res.json()));
this should work
hello! angular new version not support .map you have to install this through cmd
npm install --save rxjs-compat
via this you can enjoy with old technique .
note:
don't forget to import these lines.
import { Observable, Subject } from 'rxjs';
import 'rxjs/add/operator/map';
import 'rxjs/add/operator/catch';
thank you
This issue has been automatically locked due to inactivity.
Please file a new issue if you are encountering a similar or related problem.
Read more about our automatic conversation locking policy.
_This action has been performed automatically by a bot._
Most helpful comment
I solved issue by adding following includes in test.ts file in src/app folder in my solution
adding specific operators or extensions in component/service/etc. ts file do not make any difference.