如何从angular2中获取wordpress中的下一篇和之前的帖子
问题描述:
如何获取WordPress中角色2中的下一篇和之前的帖子?如何从angular2中获取wordpress中的下一篇和之前的帖子
我使用WordPress作为后端和角2作为前端。我通过使用WP rest API(../WP/v2/posts)获得了WordPress的所有帖子。我想下一个和以前的帖子JSON在前端展现提前采用了棱角分明2.
感谢...请帮助任何人......
import { Component, OnInit } from '@angular/core';
import { SingleService } from './singleproject.service';
import { Router, ActivatedRoute} from '@angular/router';
@Component({
selector: 'app-singleproject',
templateUrl: './singleproject.component.html',
styleUrls: ['./singleproject.component.css'],
providers: [SingleService]
})
export class SingleprojectComponent implements OnInit {
public single;
private params;
private singleDetails;
private datas;
private id;
constructor(private singleService :SingleService,
private _route:ActivatedRoute) { }
getsingle(){
this.singleService.getsingle().subscribe(singleDetails => {
this.singleDetails = singleDetails.find(datas => datas.id === +this.params.id)
});
}
ngOnInit() {
this.getsingle();
this._route.params.subscribe(params=>{
this.params = params;
});
}
}
答
getsingle(){
this.singleService.getsingle().subscribe(singleDetails => {
this.singleDetails = singleDetails.find(datas => datas.slug ==this.params.id);
this.array = singleDetails ;
this.index=this.array.indexOf(this.singleDetails);
this.nextproject= next[this.index+1];
this.previousproject= next[this.index-1]
});
}
我得到的以前和通过使用indexof下一篇文章。它为我工作
你可以发布你的代码? – vel