angular - 占位符输入文本未以角度显示
问题描述
占位符没有显示而不是定义它们。我已经为电子邮件和优先级定义了输入,但是当我运行 ng serve 并打开页面时,输入字段丢失了。
我已经检查过我的任何模块是否丢失,看起来完全没问题。我还参考了官方文档并交叉检查了我的代码。
.html 文件
<mat-horizontal-stepper [linear]="true" #stepper>
<mat-step [stepControl]="firstFormGroup"></mat-step>
<form [formGroup]="firstFormGroup">
<ng-template matStepLabel>Enter recipient info</ng-template>
<mat-form-field>
<input matInput placeholder="Email" formControlName="emailCtrl" required>
</mat-form-field>
<mat-form-field>
<input type="text" formControlName= "priorityCtrl" placeholder="Priority" matInput [matAutocomplete]= "auto" required>
<mat-autocomplete autoActiveFirstOption #auto="matAutocomplete">
<mat-option *ngFor="let priority of priorties" [value]= "priority">
{{priority}}
</mat-option>
</mat-autocomplete>
</mat-form-field>
<div>
<button mat-icon-button matStepperNext>
<mat-icon>arrow_forward</mat-icon>
</button>
</div>
</form>
<mat-step [stepControl]="secondFormGroup">
<form [formGroup]="secondFormGroup">
<mat-form-field>
<input matInput placeholder="Message" formControlName="messageCtrl" required>
</mat-form-field>
<div>
<button mat-icon-button matStepperPrevious>
<mat-icon>arrow_back</mat-icon>
</button>
<button mat-icon-button matStepperNext>
<mat-icon>mail_outline</mat-icon>
</button>
</div>
</form>
</mat-step>
<mat-step [optional]="true">
<ng-template matStepLabel>Preview</ng-template>
<p>Message Sent!</p>
<div>
<button mat-icon-button matStepperPrevious>
<mat-icon>arrow_back</mat-icon>
</button>
<button mat-icon-button (click)="stepper.reset()">
<mat-icon>refresh</mat-icon>
</button>
</div>
</mat-step>
</mat-horizontal-stepper>
这是我的 ts 文件
import { Component, OnInit } from '@angular/core';
import { FormGroup, FormBuilder, FormControl, Validators } from '@angular/forms';
@Component({
selector: 'app-message-new',
templateUrl: './message-new.component.html',
styleUrls: ['./message-new.component.scss']
})
export class MessageNewComponent implements OnInit {
firstFormGroup: FormGroup;
secondFormGroup: FormGroup;
priorites: string[] = ['High', 'Medium', 'Low'];
departments: object[] = [
{
id: 1,
name: 'Complaints'
},
{
id: 1,
name: 'Loyalty'
},
{
id: 1,
name: 'Promotions'
}
]
constructor(private formBuilder: FormBuilder) { }
ngOnInit() {
this.firstFormGroup = this.formBuilder.group({
emailCtrl: ['', Validators.required],
priorityCtrl: ['', Validators.required]
});
this.secondFormGroup = this.formBuilder.group({
messageCtrl: ['', Validators.required]
});
}
}
解决方案
推荐阅读
- amazon-web-services - 当通过 (Azure) OIDC 提供商提供 AWS 访问权限时,使用 JDBC 驱动程序连接到 AWS Athena
- javascript - 我想在 URL http://localhost/mvc/index.php/1/ASC 中获取像这样传递的参数。如何做到这一点?
- c# - c# 检查数字是否大于之前的数字并计算它
- javascript - 如何在 Firebase 中使用电子邮件和电话进行身份验证?
- javascript - 如何遍历表并让 td 元素遵循条件
- jmeter - 每个请求的自定义 JMeter 迭代次数
- memory - RISCV中的内存映射部分是什么
- python - 在python中连接两个不等尺寸的数据框
- security - 连接到 WiFi 时的 WPS VS 接入点
- html - 仅悬停在选定图像上