发布
社区首页 >问答首页 >参数'res‘隐式具有'any’类型[重复]

参数'res‘隐式具有'any’类型[重复]
EN

Stack Overflow用户
提问于 2021-03-02 05:25:43
回答 1查看 1.1K关注 0票数 0

这个问题在这里已经有答案了

Typescript: TS7006:参数'xxx‘隐式具有'any’类型

(7个答案)

9小时前就关门了。

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

参数'res‘隐式具有'any’类型。

以下是我的代码

代码语言:javascript
代码运行次数:0
复制
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中存在的问题,并按照如下步骤操作

代码语言:javascript
代码运行次数:0
复制
//"strict": true,

但对我不起作用。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2021-03-02 06:33:52

使用类型

明确地说,就像-

代码语言:javascript
代码运行次数:0
复制
observable.subscribe((res: any) => this.Success(res), (res: any) => this.Error(res));

而且-

代码语言:javascript
代码运行次数:0
复制
Success(res: any) {
    alert(res);
}
    
Error(res: any) {
    alert(res);
}

或者,设置

在您的

文件-

代码语言:javascript
代码运行次数:0
复制
"noImplicitAny": false,
票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/66429892

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档