Search code examples
angularngmodel

how to apply ngModel to an input field using Angular


Hey Guys im new in Angular,as far as i know ngModel is for two way binding right?so if i have 2 input box,can i bind one to another,so when i type something on one of them at the same time first one gets updated?

        <form >
    <div>
    <input type="text" [(ngModel)]="test" id="test1" >
    <input type="text" id="test" ">
    </div>
    </form>

i want when i write something on the second input box with the id "test" the first one shows it


Solution

  • Of course you can. Just use same ngModel in inputs. Like that:

    <input type="text" [(ngModel)]="test" id="test1" >
    <input type="text" [(ngModel)]="test" id="test2" >