Angular2 - http.post(...).map is not a function
For me the http.post(...).map()
works as expected.
I do need the import 'rxjs/Rx'
import {Component} from 'angular2/core';
import {Http} from 'angular2/http';
import 'rxjs/Rx';
@Component({
selector: 'my-app',
template: `
<h1>{{title}}</h1>
<p>Test result {{result | json}}</p>
`
})
export class App implements OnInit{
public title = 'my title';
public result : String;
constructor(private _http : Http) {
_http.post('http://jsonplaceholder.typicode.com/posts')
.map(res => res.json())
.subscribe(
data => this.result = data,
err => console.log('ERROR!!!'),
() => console.log('Got response from API', this.result)
);
}
}
See plunker example: http://plnkr.co/edit/vise2zYxZUmr1kW65mNY?p=preview
hopes this will help you to find your porblem
It seems that Angular2 beta.1 requires RxJS 5.0.0-beta.0. Perhaps it's the cause of your problem.
If I try this in my package
.json file:
"dependencies": {
"angular2": "2.0.0-beta.1",
"systemjs": "0.19.6",
"es6-promise": "^3.0.2",
"es6-shim": "^0.33.3",
"reflect-metadata": "0.1.2",
"rxjs": "5.0.0-beta.1",
"zone.js": "0.5.10"
},
And I have the error that Angular2 requires RxJS 5.0.0-beta.0.
Edit
You need to add the HTTP_PROVIDERS
within the second parameter of your bootstrap
function.
Hope it helps you, Thierry