本文介绍了无法绑定到“ngValue",因为它不是“option"的已知属性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I am trying to implement select in Angular 5 but I am constantly getting this

我已经尝试了许多 StackOverflow 问题,唯一的区别是 - 我的组件位于应用程序中的另一个模块内,最终注入到主模块中.我还尝试在内部模块中注入 FormsModule .我试过导入 ReactiveFormsModule 但没有奏效.

I've tried many StackOverflow questions already, The only difference is - My components are inside another module within the application which is at the end injected into the main module eventually. I've also tried injecting the FormsModule inside the inner module. I have tried importing ReactiveFormsModule but didn't work.

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

I've added FormsModule to imports like this

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:

[value]="ctn.value"

这篇关于无法绑定到“ngValue",因为它不是“option"的已知属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-02 02:20