Angular 4 ngModel binding not work?


Topic: Angular 4 ngModel binding not work?

Chen Xiao pro asked 7 years ago

html:
<input type="text" class="form-control" id="topicId" [(ngModel)]="testStr" mdbActive>
ts:
testStr = '';
I tried many ways to get a two-way binding, not work. Seems Mdb not support Angular 4 ngModel yet?

Chen Xiao pro answered 7 years ago

Sorry, my fault.

To use ngModel, should import FormsModule first.

app.module.ts

...
import { FormsModule } from '@angular/forms';
...
imports: [
 FormsModule,
...

html:

...
<input type="text" class="form-control" id="topicId" [(ngModel)]="comic.topic" name="topic" mdbActive>
...

 

Everything is ok!


Please insert min. 20 characters.

FREE CONSULTATION

Hire our experts to build a dedicated project. We'll analyze your business requirements, for free.

Status

Resolved

Specification of the issue
  • User: Pro
  • Premium support: No
  • Technology: MDB Angular
  • MDB Version: -
  • Device: -
  • Browser: -
  • OS: -
  • Provided sample code: Yes
  • Provided link: No