Whenever I attempt to use the subscribe function, an error pops up. I faced a similar issue with .map, but it was resolved by replacing the file found at https://raw.githubusercontent.com/Microsoft/TypeScript/Fix8518/lib/typescriptServices.js
I have recently updated Typescript to version 1.8.6 and also made sure that Visual Studio 2015 is on update 3.
The problem still persists despite my efforts, including adding
import 'rxjs/Rx';
to both the bootstrap and app.component classes.
Below is the code snippet of the service:
import { Injectable } from 'angular2/core';
import {Http, URLSearchParams} from "angular2/http";
import 'rxjs/add/operator/map';
@Injectable()
export class MediaItemService {
constructor(public http: Http) {
this.http = http;
}
//functions
get() {
// return this.mediaItems;
this.http.get("/api/MediaItem").map(response => { response.json() });
}
}
And here is where the service is utilized:
import {Component, Inject} from 'angular2/core';
import 'rxjs/Rx';
import {MediaItemComponent} from './media-item.component';
import {CategoryListPipe} from './category-list.pipe';
import {MediaItemService} from './media-item.service';
@Component({
selector: 'media-item-list',
directives: [MediaItemComponent],
pipes: [CategoryListPipe],
providers: [MediaItemService],
templateUrl: 'app/media-item-list.component.html',
styleUrls: ['app/media-item-list.component.css']
})
export class MediaItemListComponent {
constructor(private mediaItemService: MediaItemService) {
//.subscribe(mediaItems => {
// this.mediaItems = mediaItems;
//});
}
ngOnInit() {
this.mediaItems = this.mediaItemService.get().subscribe(mediaItems => {
this.mediaItems = mediaItems;
});
}
onMediaItemDeleted(mediaItem) {
this.mediaItemService.delete(mediaItem);
}
mediaItems;
}
Lastly, here is the content of the package.json file:
{
"version": "1.0.0",
"name": "TestFunWithAngi",
"private": true,
"dependencies": {
"angular2": "^2.0.0-beta.17",
"systemjs": "^0.19.31",
"es6-promise": "^3.2.1",
"es6-shim": "^0.35.1",
"reflect-metadata": "^0.1.3",
"rxjs": "^5.0.0-beta.9",
"tsd": "^0.6.5",
"zone.js": "^0.6.12"
},
"devDependencies": {
"typescript": "^1.8.10",
"typings": "^0.8.1",
"grunt": "1.0.1",
"grunt-contrib-copy": "1.0.0",
"grunt-contrib-uglify": "1.0.1",
"grunt-contrib-watch": "1.0.0",
"grunt-ts": "5.5.1"
}
}