angular – Typescript Error预期0个参数,但在Ionic Framework中得到2个

前端之家收集整理的这篇文章主要介绍了angular – Typescript Error预期0个参数,但在Ionic Framework中得到2个前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
打字稿编译器给了我这个错误

typescript: src/pages/login/login.ts,line: 33
Expected 0 arguments,but got 2.
L32: this.auth.loginAPI(this.registerCredentials)
L33: .subscribe(response => {

使用此代码(2个文件):

// auth-provider.ts
public loginAPI(credentials: {email:string,password:string}) {
  return this.http.post(this.apiUrl,data);
}

// login.ts
this.auth.loginAPI(this.registerCredentials)
  .subscribe(response => { 
    console.log(response);
  },err => {
    console.log(err);
  });

有趣的是代码工作(我编辑任何文件,我的离子服务器重新加载和页面呈现没有任何问题).

任何的想法?

环境
cli包:(/usr/local/lib / node_modules)

@ionic/cli-utils  : 1.19.0
ionic (Ionic CLI) : 3.19.0

全球套餐:

cordova (Cordova CLI) : 7.0.1

本地包裹:

@ionic/app-scripts : 3.1.5
Cordova Platforms  : ios 4.4.0
Ionic Framework    : ionic-angular 3.9.2

系统:

Node  : v8.9.3
npm   : 5.5.1
OS    : macOS High Sierra
Xcode : Xcode 9.2 Build version 9C40b

解决方法

问题在于loginAPI函数定义.
将返回类型添加到Observable< any>让编译器开心并解决了这个问题.

// auth-provider.ts
public loginAPI(credentials: {email:string,password:string}):Observable<any> {
  return this.http.post(this.apiUrl,data);
}

我仍然不太了解为什么,但至少现在它编译没有任何错误.

猜你在找的Angularjs相关文章