0
我正在設計的東西,將採取一種功能,並激活它; upSwipe()。打電話時,我想發佈到網址:http://localhost:8000/areas/fun/736993854/spread/1/空身。控制檯在本文中輸出正確的url。然而,下面的代碼行,http.post不工作/不張貼。我不太清楚爲什麼。 這裏有什麼幫助嗎?http.post()不張貼即使url正確
import { Component, OnInit } from '@angular/core';
import { Http, Headers, RequestOptions, Response } from '@angular/http';
import { FormsModule } from '@angular/forms';
import { Post} from '../_models/index';
import { AuthenticationService, PostService, SpreadService, AreaService} from '../_services/index';
@Component({
templateUrl: 'home.component.html'
})
export class HomeComponent implements OnInit {
posts: Post[] = [];
constructor(private http: Http,
private postService: PostService,
private spreadService: SpreadService,
private areaService: AreaService,
private authenticationService: AuthenticationService) { }
ngOnInit() {
// get posts from secure api end point
this.postService.getPosts()
.subscribe(post => {
this.posts = post;
});
}
upSwipe() {
console.log('upSwipe worked');
const headers = new Headers();
headers.append('Authorization', 'token ' + this.authenticationService.token);
headers.append('Content-Type', 'application/json');
const options = new RequestOptions({
headers: headers,
});
// get areas from api
console.log('http://localhost:8000/areas/' + this.areaService.currentAreaName + '/' + this.posts[0].id + '/spread/1/');
this.http.post('http://localhost:8000/areas/' + this.areaService.currentAreaName + '/' + this.posts[0].id + '/spread/1/', {}, options);
this.ngOnInit();
}
downSwipe() {
console.log('downSwipe worked');
}
fun() {
this.areaService.currentArea = 0;
this.areaService.currentAreaName = 'fun';
this.ngOnInit();
}
information() {
this.areaService.currentArea = 1;
this.areaService.currentAreaName = 'information';
this.ngOnInit();
}
}
所以很明顯哈哈謝謝 –