How to fill a text box using ng-bind?

I am new to AngularJS and I am following this link and am curious to experiment with a text box using ng-bind. But it does not work.

<html> <title>AngularJS First Application</title> <body> <h1>Sample Application</h1> <div ng-app=""> <p>Enter your Name: <input type="text" ng-model="name"></p> <input type ="text" ng-bind="name" /> </div> <script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.3.14/angular.min.js"></script> </body> </html> 

How can I populate a text box using ng-bind?

+7
angularjs
source share
1 answer

Like, the ngBind attribute tells Angular to replace text content the specified HTML element with the value of the expression and update the text content when the value of this expression changes, you cannot bind to the input box:

 <input type ="text" ng-bind="name" /> 

You can use ng-value instead

 <input type="text" ng-value="name" /> 

or you can fill in the input field using the model in the value attribute.

 <input type="text" value="{{name}}" /> 

See codepen

+16
source share

All Articles