× {{alert.msg}} Never ask again
Get notified about new tutorials RECEIVE NEW TUTORIALS

AngularJS - Value attribute on an input text box is ignored when there is a ng-model used?

Dale Lotts
Mar 18, 2015
<p>This is a slight modification to the earlier answers...</p> <p>There is no need for $parse</p> <pre><code>angular.directive('input', [function () { 'use strict'; var directiveDefinitionObject = { restrict: 'E', require: '?ngModel', link: function postLink(scope, iElement, iAttrs, ngModelController) { if (iAttrs.value &amp;&amp; ngModelController) { ngModelController.$setViewValue(iAttrs.value); } } }; return directiveDefinitionObject; }]); </code></pre> <p>This tip was originally posted on <a href="http://stackoverflow.com/questions/10610282/AngularJS%20-%20Value%20attribute%20on%20an%20input%20text%20box%20is%20ignored%20when%20there%20is%20a%20ng-model%20used?/26600872">Stack Overflow</a>.</p>

Get New Tutorials Delivered to Your Inbox

New tutorials will be sent to your Inbox once a week.

comments powered by Disqus