Siy*_*yah 1 wordpress ionic-framework angular ionic4
我不断收到以下错误:
[ng] ERROR in src/app/home/home.page.ts(34,10): error TS2339: Property 'router' does not exist on type 'HomePage'.
Run Code Online (Sandbox Code Playgroud)
我正在尝试将Wordpress 与 Ionic 4结合起来,到目前为止我设法从我的网站获取最近的帖子。现在我想让这些可点击并导航到它们,但由于我的代码片段中的这段代码,我收到了上面提到的错误home.page.ts
openPost(postId) {
this.router.navigateByUrl('/post/' + postId);
}
Run Code Online (Sandbox Code Playgroud)
完整页面:
import { Router } from '@angular/router';
import { Component } from '@angular/core';
import { LoadingController } from '@ionic/angular';
import { WordPressRestapiService, Post } from '../services/wordpress-restapi.service';
@Component({
selector: 'app-home',
templateUrl: 'home.page.html',
styleUrls: ['home.page.scss'],
})
export class HomePage {
categoryId: number;
private posts : Post[] = [];
constructor(
public loadingController: LoadingController,
private wordpressService: WordPressRestapiService) { }
async ngOnInit() {
const loading = await this.loadingController.create();
await loading.present();
this.loadPosts().subscribe((posts: Post[]) => {
this.posts = posts
loading.dismiss();
});
}
loadPosts() {
return this.wordpressService.getRecentPosts(this.categoryId);
}
openPost(postId) {
this.router.navigateByUrl('/post/' + postId);
}
}
Run Code Online (Sandbox Code Playgroud)
我也尝试过删除“this”,但我在 SO 上找不到的任何东西都对我有用。有人有什么想法吗?
在构造函数中注入路由器
constructor(
public loadingController: LoadingController,
private wordpressService: WordPressRestapiService,
private router: Router) { }
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
7269 次 |
| 最近记录: |