-2

What is the exact role of ng-model in AngularJS? Can anyone explain with example? And when we can use ng-model?

svarog
  • 9,477
  • 4
  • 61
  • 77

1 Answers1

0

ng-model in angular js is basically a directive which binds the value of your model with the controller. Angular js Supports two way data binding which means when the value of variable changes in the model it will be reflected in the controller and vice versa. Here is a sample code which shows the two way data binding of angular js.

<!DOCTYPE html>
<html>
    <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.4.8/angular.min.js"></script>
    <body>

        <div ng-app="">
 
            <p>Input something in the input box:</p>
            <p>Name : <input type="text" ng-model="name" placeholder="Enter name here"></p>
            <h1>Hello {{name}}</h1>

        </div>

    </body>
</html>

You could find the details at tutorialspoint, w3school

Nitheesh
  • 19,238
  • 3
  • 22
  • 49