错误TS2339:类型“ HomePage”上不存在属性“ router”

时间:2019-06-07 13:49:02

标签: angular wordpress ionic-framework ionic4

我经常遇到以下错误:

#include <list>
#include <map>
#include <string>

class IntWithString {
private:
  int a;
  std::string s;

public:
  IntWithString(int a, std::string s) : a(a), s(s) {}
  std::string getString() { return s; }
  int getInt() { return a; }
};

namespace {
std::map<std::string, std::list<IntWithString *> > m;
}

void appendMap(IntWithString *a) {
  auto it = m.find(a->getString());
  if (it != m.end()) {
    m[a->getString()].push_back(a);
  } else {
    std::list<IntWithString *> l;
    l.push_back(a);
    m[a->getString()] = l;
  }
}

int main() {
  IntWithString a(10, "ten");
  IntWithString b(11, "ten");
  appendMap(&a);
  appendMap(&b);
  return 0;
}

我正在尝试将 Wordpress与Ionic 4 结合在一起,到目前为止,我设法从我的网站上获取了最近的帖子。 现在,我想使这些按钮可点击并导航到它们,但是由于我的[ng] ERROR in src/app/home/home.page.ts(34,10): error TS2339: Property 'router' does not exist on type 'HomePage'.

中有此代码段,我遇到了上面提到的错误
home.page.ts

整页:

  openPost(postId) {
    this.router.navigateByUrl('/post/' + postId);
  }

我也尝试过删除“ this”,但是我在SO上找不到任何对我有用的东西。有人知道吗?

1 个答案:

答案 0 :(得分:3)

将路由器插入构造函数中

constructor(
  public loadingController: LoadingController,
  private wordpressService: WordPressRestapiService,
  private router: Router) { }