gpt4 book ai didi

angular - 无法绑定(bind)到 'ngValue',因为它不是 'option' 的已知属性

转载 作者:太空狗 更新时间:2023-10-29 17:00:59 51 4
gpt4 key购买 nike

我正在尝试在 Angular 5 中实现 select,但我不断得到这个

enter image description here

我已经尝试过很多 StackOverflow 问题,唯一的区别是 - 我的组件位于应用程序的另一个模块中,该模块最终注入(inject)到主模块中。我还尝试将 FormsModule 注入(inject)到内部模块中。我已尝试导入 ReactiveFormsModule 但没有成功。

我已将 FormsModule 添加到这样的导入中

import { BrowserModule } from '@angular/platform-browser';
import { NgModule } from '@angular/core';
import { FormsModule } from '@angular/forms';
import { AppRoutingModule } from './app-routing.module';

@NgModule({
declarations: [
...CombineComponents
],
imports: [
BrowserModule,
FormsModule,
AppRoutingModule,
HttpClientModule
]
});

这是我的组件标记

<label for="ctn" class="d-inline-block pl-1 semi-bold">Current active number</label>
<select
#selectElem
class="custom-select"
id="ctn"
(change)="onCTNChange(selectElem.value)"
formControlName="state"
>
<option value="" disabled>Choose a state</option>
<option *ngFor="let ctn of availableCTN" [ngValue]="ctn.value">
{{ctn.text}}
</option>
</select>

最佳答案

使用:

[value]="ctn.value"

关于angular - 无法绑定(bind)到 'ngValue',因为它不是 'option' 的已知属性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48444765/

51 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com