-1

I got a problem

My hellow.component.html is:

<form>
    <input ng-model="hello" type="text">
</form>
<p>{{hello}}</p>

and hellow.component.ts is:

import { Component, OnInit } from '@angular/core';

@Component({
  selector: 'app-hellow',
  templateUrl: './hellow.component.html',
  styleUrls: ['./hellow.component.css']
})
export class HellowComponent implements OnInit {

  hello:string ='';
  constructor() { }

  ngOnInit() {
  }

}

Can you answer
If I write something in input, {{hello}} string interpolation is not actualized by controller. Can you help me with this matter?

also tried with:

<input [(ngModel)]="hello" type="text">

Thank you, a lot.

3 Answers3

0

Did you import FormsModule?

import { FormsModule } from '@angular/forms';
Roham Rafii
  • 2,929
  • 7
  • 35
  • 49
0

When using the ngModel within tags, you'll also need to supply a name attribute so that the control can be registered with the parent form under that name. Try this.

 <form>
        <input name="hello" [(ngModel)]="hello" type="text">
  </form>
    <p>{{hello}}</p>
Vikas
  • 11,859
  • 7
  • 45
  • 69
0

Problem is solved I forgot to add name="hello" attribute in input tag
Thanks a lot for help!