gpt4 book ai didi

javascript - Ionic4 错误 TS2554 : Expected 1 arguments, 但得到 0

转载 作者:行者123 更新时间:2023-11-30 13:58:04 25 4
gpt4 key购买 nike

当我使用 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获取完整说明。

关于javascript - Ionic4 错误 TS2554 : Expected 1 arguments, 但得到 0,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56832133/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com