node.js - 'string' 类型的参数不可分配给'FormControl' 类型的参数
问题描述
这是我的进口
import { Component, OnInit, OnChanges } from '@angular/core';
import { HttpService } from ".././http.service";
import { FormControl, Validators } from "@angular/forms";
这就是我初始化表单的方式
emailFormControl = new FormControl("", [
Validators.required,
Validators.email
]);
nameFormControl = new FormControl("", [
Validators.required,
Validators.minLength(4)
]);
这是我的发送功能
send() {
this.loading = true;
this.buttonText = "Submiting...";
let user = {
name: this.nameFormControl.value,
email: this.emailFormControl.value
}
this.http.sendnotif("http://localhost:8080/send-notif", user).subscribe(
data => {
let res:any = data;
console.log(
`an email has been sent successfully to ${user.name} and the message id is ${res.messageId}`
);
},
err => {
console.log(err);
this.loading = false;
this.buttonText = "Submit";
},() => {
this.loading = false;
this.buttonText = "Submit";
}
);
}
}
这是html
<form style="width: 50%; margin: auto">
<mat-card>
<h1>Please fill the form </h1>
<mat-form-field style="width: 100%">
<input matInput placeholder="Name" [formControl]="nameFormControl" />
<mat-error *ngIf="nameFormControl.hasError('minlength')">
Name must be at least 4 characters long.
</mat-error>
<mat-error *ngIf="nameFormControl.hasError('required')">
Name is <strong>required</strong>
</mat-error>
</mat-form-field>
<mat-form-field style="width: 100%">
<input matInput placeholder="Email" [formControl]="emailFormControl"/>
<mat-error *ngIf="emailFormControl.hasError('email')">
Please enter a valid email address
</mat-error>
<mat-error *ngIf="emailFormControl.hasError('required')">
Email is <strong>required</strong>
</mat-error>
</mat-form-field>
<button
mat-raised-button
[disabled]="emailFormControl.invalid || nameFormControl.invalid || loading"
color="primary"
(click)="send()"
>
{{buttonText}}
</button>
</mat-card>
</form>
我收到的错误是“'string'类型的参数不能分配给'FormControl'类型的参数。” 它指向“http://localhost:8080/send-notif”任何我如何解决这个问题的建议我几乎尝试了一切
解决方案
推荐阅读
- java - 尽管我的代码返回字符串,但该函数仍希望返回字符串
- angular - 具有多个输入的 FormControlName 的 ControlValueAccessor
- swift - swift 4 中的应用内购买无效的产品标识符
- python - 模块“theano”没有属性“编译”
- android - 从 5.1.1 版本的经纬度获取地址
- symfony - FOSOAuthServerBundle + Symfony 4 配置 - 无法导入路由
- html - 缓慢的 Vue 样式绑定
- google-cloud-vision - 带有谷歌云存储的谷歌 API 愿景
- angular - Angular canActive 与 observable
- php - 调用非对象上的成员函数 getCollection() 以在 magento 中加载模型