Angular2 http.post(http://127.0.0.1:555)
Chrome developer network show
post "http://127.0.0.1:4444/127.0.0.1:5555"
is not found
"http://127.0.0.1:5555"
is node server
"http://127.0.0.1:4444"
is angular2 server
Why the two stack together?
post component import { Component, OnInit } from '@angular/core'; import {ActivatedRoute, Router } from '@angular/router'; import {PostDetailService} from './post-detail.service';
@Component({
selector: 'app-post-detail',
templateUrl: './post-detail.component.html',
styleUrls: ['./post-detail.component.scss']
})
export class PostDetailComponent implements OnInit {
postDetail= {
title: '',
userName: '',
postWriteTime: 0,
readTimes: 0,
commentTimes: 0
};
opts = {
url: 'http:127.0.0.1:5555/postDetail',
body: '',
};
constructor(private router: Router, private activateRoute: ActivatedRoute, private postDetailService: PostDetailService) { }
ngOnInit() {
this.activateRoute.params.subscribe((params) => {
this.opts.body = params['postId'];
console.log(params, 'params');
});
this.getPostDetailById();
}
getPostDetailById() {
this.postDetailService.getPostDetail(this.opts).subscribe(
res => {
console.log(res, 'res');
},
err => console.log(err),
() => console.log("complete"));
}
}
import { Injectable } from '@angular/core';
import {Http, Response} from '@angular/http';
import {Observable} from 'rxjs/Rx';
@Injectable()
export class PostDetailService {
constructor(private http: Http) {}
getPostDetail(opts): Observable<any> {
console.log(opts, 'opts');
return this.http.post(opts.url, opts.body).
map((res: Response) => res.json())
.catch((error: any) => Observable.throw(error || 'Server error'));
}
}