我使用离子服务测试时,有一段代码出现问题。 我无法弄清楚 npm 更新后出了什么问题。
在终端上显示,
src / app / pages / posts / posts.ts(30,27)中的[ng]错误:错误TS2554: 预期有1个参数,但有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();
}
}
答案 0 :(得分:2)
在您的代码中
const loading = await this.loadingController.create();
需要类似
的参数 create(options?: LoadingOptions | undefined) => Promise<HTMLIonLoadingElement>
。
但是您传递了0个参数。请传递参数它将解决。
Follow this document获取完整说明。