如何在angular2中从wordpress获取下一篇和上一篇文章
how to get next and previous posts from wordpress in angular2
如何在 angular 2 中从 WordPress 获取下一篇和上一篇文章?
我使用 WordPress 作为后端,angular 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;
});
}
}
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 获取上一篇和下一篇文章。它对我有用
如何在 angular 2 中从 WordPress 获取下一篇和上一篇文章?
我使用 WordPress 作为后端,angular 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;
});
}
}
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 获取上一篇和下一篇文章。它对我有用