加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > 安全 > 正文

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

发布时间:2020-12-17 17:29:41 所属栏目:安全 来源:网络整理
导读:打字稿编译器给了我这个错误 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.tspublic loginAP
打字稿编译器给了我这个错误

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

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

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读