无法绑定到"ngValue",因为它不是"option"的已知属性 [英] Can't bind to 'ngValue' since it isn't a known property of 'option'

查看:95
本文介绍了无法绑定到"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"的已知属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆