Ionic4 错误 TS2554:需要 1 个参数,但得到 0 个

Ionic4 Error TS2554: Expected 1 arguments, but got 0

我有一段代码在使用 ionic serve 进行测试时出现问题。 npm 更新后我无法弄清楚出了什么问题。

In the terminal it is showing,

[ng] ERROR in src/app/pages/posts/posts.ts(30,27): error TS2554: Expected 1 arguments, but got 0.

希望有人能指导我。 提前致谢。

import { Component,OnInit,ViewEncapsulation } from '@angular/core';
import { LoadingController,NavController,ModalController } from '@ionic/angular';
import { Router } from '@angular/router';
import { WordPressRestapiService, Post } from '../../providers/wordpress-service';
/*
  Generated class for the Posts page.

  See http://ionicframework.com/docs/v2/components/#navigation for more info on
  Ionic pages and navigation.
*/
@Component({
  selector: 'page-posts',
  templateUrl: 'posts.html',
  styleUrls: ['posts.scss'],
  encapsulation: ViewEncapsulation.None
})

export class PostsPage {
  categoryId: number;
  private posts : Post[] = [];

  constructor(
      public loadingController: LoadingController,
      private wordpressService: WordPressRestapiService,
      public navCtrl: NavController,
      public router: Router,
      public modalView: ModalController) { }

  async ngOnInit() {
    const loading = await this.loadingController.create();
    await loading.present();

    this.loadPosts().subscribe(res => {
      this.posts = [...this.posts, ...res];
      loading.dismiss();
    });
  }

  loadPosts() {
    return this.wordpressService.getRecentPosts(this.categoryId);
  }


  openPost(postId) {
  this.router.navigateByUrl('/singlepost/' + postId);
  this.modalView.dismiss();
  }

}
import { Component,OnInit,ViewEncapsulation } from '@angular/core';
import { LoadingController,NavController,ModalController } from '@ionic/angular';
import { Router } from '@angular/router';
import { WordPressRestapiService, Post } from '../../providers/wordpress-service';
/*
  Generated class for the Posts page.

  See http://ionicframework.com/docs/v2/components/#navigation for more info on
  Ionic pages and navigation.
*/
@Component({
  selector: 'page-posts',
  templateUrl: 'posts.html',
  styleUrls: ['posts.scss'],
  encapsulation: ViewEncapsulation.None
})

export class PostsPage {
  categoryId: number;
  private posts : Post[] = [];

  constructor(
      public loadingController: LoadingController,
      private wordpressService: WordPressRestapiService,
      public navCtrl: NavController,
      public router: Router,
      public modalView: ModalController) { }

  async ngOnInit() {
    const loading = await this.loadingController.create();
    await loading.present();

    this.loadPosts().subscribe(res => {
      this.posts = [...this.posts, ...res];
      loading.dismiss();
    });
  }

  loadPosts() {
    return this.wordpressService.getRecentPosts(this.categoryId);
  }


  openPost(postId) {
  this.router.navigateByUrl('/singlepost/' + postId);
  this.modalView.dismiss();
  }

}

在你的代码中

const loading = await this.loadingController.create();

需要像

这样的参数

create(options?: LoadingOptions | undefined) => Promise<HTMLIonLoadingElement>

但是你传递了 0 个参数。请传递它将解决的论点。

Follow this document 获取完整说明。