Reputation: 4998
I have an input field. I want to print on the screen in real time anything that i type in.
The code below prints 'Hello world' with an input field. But does not performs any real time binding.
File: app.component.html
<h1>Hello world</h1>
<input type="text">
But the moment I add
[(ngModule)]
. Everything vanishes even the Hello world. Though the cmd prompt says Compiled successfully.
<h1>Hello world</h1>
<input type="text" [(ngModel)]="name">
<p>{{ name }}</p>
My app.component.ts file is:
import { Component } from '@angular/core';
@Component({
selector: 'app-root',
templateUrl: './app.component.html'
})
export class AppComponent {
name = '';
}
I have also uploaded my code on GitHub for your convenience
Upvotes: 1
Views: 688
Reputation: 22203
Import FormsModule
in app.module
@NgModule({
imports: [
FormsModule
]
I think you have missed to add all the files in GitHub
Upvotes: 5