What is the purpose of using the ng-model
directive in this AngularJS example? Although the code works without it, simply removing the ng-model
directive and setting the myCol
variable to a valid background color value will suffice. So why include the ng-model
directive?
<!DOCTYPE html>
<html>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.6.9/angular.min.js"></script>
<body>
<p>Change the value of the input field:</p>
<div ng-app="" ng-init="myCol='lightblue'">
<input style="background-color:{{myCol}}" ng-model="myCol">
</div>
<p>AngularJS evaluates the expression and returns the result.</p>
<p>The input box's background color will reflect what you type in the input field.</p>
</body>
</html>