title: How to properly clean form with invalid input from AngularJS controller?
body: <p>I have an AngularJS form that contains - among other fields - one of type <code>url</code>. The latter is important as this forces the corresponding input to be a valid URL.</p>
  
  <p>Under certain conditions (for instance, a modal dialog with such a form is to be closed), I want to clear that form programmatically. For that purpose, I implemented method <code>reset</code> that basically clears the corresponding form model by setting <code>$scope.formData = {}</code>. Thus, it sets the form model to a new, blank object.</p>
  
  <p>While that assignment clears all <strong>valid</strong> fields in the rendered HTML form, it does <strong>not</strong> clear <strong>invalid</strong> fields, like an invalid URL. For instance, if the user would provide invalid input <code>ht://t/p</code> as URL, that input would not be removed from the rendered form.</p>
  
  <p>I think this is due to the fact that any invalid URL is not reflected by the model - such an invalid URL just wouldn't "make" it to the model because it does not pass validation in the <code>NgModelController#$parsers</code> array. Thus, in the model - there is no URL at all. Consequently, resetting the form model to <code>{}</code> cannot actually <em>change</em> the model's URL as it has not been set yet.</p>
  
  <p>However, if method <code>reset</code> explicitly sets field <code>$scope.formData.url = ""</code>, the invalid URL will be cleared properly (at least, the rendered form won't show it anymore). This is caused by the <em>explicit</em> change of the URL in the model. However, now, model variable <code>formData.url</code> contains the empty string (well, not surprisingly), while by using <code>= {}</code>, all fields would be <code>undefined</code> instead.</p>
  
  <p>While assigning individual fields to <code>""</code> works as workaround for simple forms, it quickly becomes cumbersome for more complex forms with many fields.</p>
  
  <p>Thus, how could I programmatically reset the form efficiently and effectively - including all invalid input fields as well?</p>
  
  <p>I created a Plunker at <a href="http://plnkr.co/c2Yhzs">http://plnkr.co/c2Yhzs</a> where you can examine and run a complete example showing the above effect.</p>