无法绑定到"ngModelOptions",因为它不是Angular子模块中"input"的已知属性 [英] Can't bind to 'ngModelOptions' since it isn't a known property of 'input' in submodule in Angular
本文介绍了无法绑定到"ngModelOptions",因为它不是Angular子模块中"input"的已知属性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我的项目中有几个子模块,其中之一是SharedModule(共享所有模块).
I have several submodules in my project, one of them, is the SharedModule (which shares the modules in common for all).
SharedModule包括FormsModule和ReactiveFormsModule导入. 我将此模块导入到要使用表单的模块中,但是不起作用.
The SharedModule includes the FormsModule and ReactiveFormsModule import. I import this module into the module that I want to use the forms, but it doesn't work.
组件模板块
<div class="md-form">
<input [formControl]="personGroup.get('medication')" [ngModelOptions]="{standalone: true}" mdbActive type="text" id="medication" class="form-control" #medication>
<label for="medication" class="">Ingrese el medicamento</label>
<button class="btn btn-success btn-sm" (click)="addMedication(medication.value)">
<i class="fa fa-plus" aria-hidden="true"></i>
</button>
子模块
@NgModule({
declarations: [
...
],
imports: [
...
SharedModule,
...
],
exports: [
...
]
})
export class PeopleModule { }
共享模块
import { NgModule, NO_ERRORS_SCHEMA } from '@angular/core';
import { CommonModule } from '@angular/common';
import { MDBBootstrapModule } from 'angular-bootstrap-md';
import { FormsModule, ReactiveFormsModule } from "@angular/forms";
@NgModule({
imports: [
CommonModule,
...
FormsModule,
ReactiveFormsModule,
...
],
exports: [
...
FormsModule,
ReactiveFormsModule,
...
],
declarations: [
...
],
schemas: [ NO_ERRORS_SCHEMA ],
})
export class SharedModule { }
推荐答案
要使用ngModelOptions
,应将ngModel
指令应用于输入元素:
In order to use ngModelOptions
, the ngModel
directive should be applied to the input element:
<input ngModel [ngModelOptions]="{standalone: true}" ... />
因为ngModelOptions
是ngModel
指令的属性.
这篇关于无法绑定到"ngModelOptions",因为它不是Angular子模块中"input"的已知属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文