【问题标题】:Parameter 'res' implicitly has an 'any' type [duplicate]参数'res'隐式具有'any'类型[重复]
【发布时间】:2021-05-31 10:27:37
【问题描述】:

我正在尝试将角度 HTML 页面数据发送到 MVC 核心。最后有兴趣得到回应。所以我正在使用 subscribe 方法,但它显示了这个错误 -

参数“res”隐含的类型为“any”。

这是我的代码

import { Component } from '@angular/core';
import { Patient } from './app.model';
import {HttpClient} from "@angular/common/http"
import { Observable, observable } from 'rxjs';
@Component({
  selector: 'app-root',
  templateUrl: './app.component.html',
  styleUrls: ['./app.component.css']
})
export class AppComponent {

    patientObj: Patient = new Patient();

    constructor(public httpClient:HttpClient){}

    Add() { 
        //https://localhost:44331/Patient/SubmitPatient ServerSide Page for display record
        alert(this.patientObj.id);
        var observable=this.httpClient.post("https://localhost:44331/Patient/SubmitPatient", this.patientObj);
    
        observable.subscribe(res=> this.Success(res), res=> this.Error(res));
    }
    
    Success(res) {
        alert(res);
    }
    
    Error(res) {
        alert(res);
    }
}


编辑 1
我已经解决了 StackOverflow 中存在的问题,并按照如下步骤操作

//"strict": true,

但对我不起作用。

【问题讨论】:

标签: angular


【解决方案1】:

明确使用any 类型,例如 -

observable.subscribe((res: any) => this.Success(res), (res: any) => this.Error(res));

和-

Success(res: any) {
    alert(res);
}
    
Error(res: any) {
    alert(res);
}

或者,在您的 tsconfig.json 文件中将 noImplicitAny 设置为 false -

"noImplicitAny": false,

【讨论】:

  • 谢谢先生,它现在正在与res:any合作
猜你喜欢
  • 2018-09-23
  • 2018-09-25
  • 2017-11-30
  • 2021-12-24
  • 2019-03-15
  • 1970-01-01
  • 2019-06-28
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多