如何从angular2中的wordpress获取下一篇和之前的帖子

时间:2017-08-17 03:52:03

标签: wordpress angular angular2-services

如何从角度2中的WordPress获取下一个和上一个帖子?

我使用WordPress作为后端,将角度2作为前端。我通过使用WP rest API(../WP/v2/posts)获得了WordPress的所有帖子。我希望使用angular 2来获得下一个和之前的帖子json在前端显示。

提前感谢...请帮助任何人...

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;


 });
  }

}

1 个答案:

答案 0 :(得分:0)

class Converter {
    public A bToA(B b){
        int a1 = b.getB1();// Information hiding and encapsulation broken
        //       ---------
        return new A(a1);
    }
}

我使用indexof获取上一篇和下一篇文章。它为我工作