Calvin Seng
Calvin Seng

Reputation: 193

Ionic4 Error TS2554: Expected 1 arguments, but got 0

I have a piece of code that has issue when I am testing with ionic serve. I Cannot figure out what went wrong after npm update.

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.

Hope someone can guide me out. Thanks in advance.

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();
  }

}

Upvotes: 1

Views: 1032

Answers (1)

user11707511
user11707511

Reputation:

In your code

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

needs an argument like

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

But you pass 0 arguments. Kindly pass argument it will solve.

Follow this document for full instructions.

Upvotes: 2

Related Questions