簡體   English   中英

angular2 http.post原始地址和目標地址在一起

[英]angular2 http.post The original address and destination address are together

Angular2 http.post(http://127.0.0.1:555)

找不到Chrome開發者網絡的展示post "http://127.0.0.1:4444/127.0.0.1:5555"

"http://127.0.0.1:5555"是節點服務器

"http://127.0.0.1:4444"是angular2服務器

為什么兩者堆疊在一起?

從'@ angular / core'發布組件導入{Component,OnInit}; 從“ @ angular / router”導入{ActivatedRoute,Router}; 從'./post-detail.service'導入{PostDetailService};

@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'));
    }
}

網址應為

url: 'http://127.0.0.1:5555/postDetail',

代替

url: 'http:127.0.0.1:5555/postDetail',

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM