Justin Castillo
Justin Castillo

Reputation: 95

Can't bind to 'ngModelOptions' since it isn't a known property of 'input' in submodule in Angular

I have several submodules in my project, one of them, is the SharedModule (which shares the modules in common for all).

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.

Component template chunk

<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>

SubModule

@NgModule({
  declarations: [    
    ...
  ],
  imports: [
    ...
    SharedModule,
    ...
  ],
  exports: [
    ...
  ]
})
export class PeopleModule { }

The SharedModule

 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 { }

Upvotes: 6

Views: 12844

Answers (1)

Martin Parenteau
Martin Parenteau

Reputation: 73761

In order to use ngModelOptions, the ngModel directive should be applied to the input element:

<input ngModel [ngModelOptions]="{standalone: true}" ... />

because ngModelOptions is a property of the ngModel directive.

Upvotes: 11

Related Questions