angular - 参数“res”隐式具有“any”类型
问题描述
我正在尝试将角度 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,
但对我不起作用。
解决方案
显式使用类型any
,例如 -
observable.subscribe((res: any) => this.Success(res), (res: any) => this.Error(res));
和 -
Success(res: any) {
alert(res);
}
Error(res: any) {
alert(res);
}
或者,在您的文件中设置noImplicitAny
为-false
tsconfig.json
"noImplicitAny": false,
推荐阅读
- flowtype - 如何键入注释“函数包装器”(返回具有与其参数相同签名的函数的函数)
- android - 如何从 Google Play 应用或游戏列表页面中删除屏幕截图
- r - 比较线性、非线性和不同参数化非线性模型的方法
- java - 如何针对较大的 n 值修复我的快速排序算法?(并且当数组不是随机的时)
- openedge - 如果 FOR EACH 循环中没有任何记录匹配,如何给出错误消息?
- javascript - 如何根据输入文本搜索显示所有嵌套列表元素?
- elasticsearch - 在所有字段上进行 Multi_match 弹性搜索,并提升到特定字段
- python - 如何计算张量 A 沿轴的加权平均值,权重由张量流中的张量 B 指定?
- javascript - 处理来自 ElasticSearch 的对象 - 我需要重建它吗?
- laravel - 在 docker 中通过 composer 安装 laravel 时出错