angular - Angular 8 选择的选项编号和字母
问题描述
我选择的选项有问题
when the name_step = "ABCD" is selected but
当未选择 name_step = "1" 时。
为什么会发生这种情况,即使我将两者都设置为字符串
这是我的代码:
<option *ngFor="let step of listStep | keyvalue" value={{step.value.id}} selected="{{step.value.name === name_step ? 'selected' : '' }}">
{{ step.value.name | titlecase }}</option>
我有 3 个选项
option 1 [id = 1, name = "1"],
option 2 [id = 2, name = "2"],
option 3 [id = 3, name = "ABCD"]
这个代号 name_step :
this.name_step = params['params']['name_step'];
解决方案
我不确定我的问题是否正确,但您可以问这样的问题吗
<mat-form-field>
<mat-label>Cars</mat-label>
<select matNativeControl required>
<option *ngFor="let step of listStep " value={{step.id}} selected="{{step.name == name_step ? 'selected' : '' }}">
{{ step.name | titlecase }}</option>
</select>
</mat-form-field>
ts文件代码
name_step='ABCD';
listStep: any[] = [
{ id: 1, name: "1" },
{ id: 2, name: "2" },
{ id: 3, name: "ABCD" }
];
推荐阅读
- javascript - 如何在 Node.js 中发送真实数据?
- html - Angular Bootstrap 4 Navbar 不会切换和 navbar-dark 问题
- c# - 不能画一条简单的线
- html - 放置 div 块
- spring - Spring Security:自定义 UserDetails 和 GrandtedAuthority 实现
- asp.net-mvc-5 - 为什么我不应该使用 MVC Jsonresult 而不是 apicontroller get 方法
- cmd - 创建用于切换 python 版本的 *.bat 文件
- python - 处理一个 Numpy 数组的极端情况以进行迭代
- java - JNI 代码返回字符串但得到错误 java.lang.UnsatisfiedLinkError: com.package.openGeoDb()Ljava/lang/String;
- python - 如何平滑 LSTM 输出