title: Angular manually update ngModel and set form to dirty or invalid?
body: <p>I have a form and an underlying model like this</p>
  
  <p>From component</p>
  
  <pre><code>myTextModel: string;
  updateMyTextModel(): void {
      this.myTextModel = "updated model value";
      //todo- set form dirty (or invalid or touched) here
  }
  </code></pre>
  
  <p>Html template</p>
  
  <pre><code>&lt;form #testForm="ngForm" id="testForm"&gt;
    &lt;input type="text" id="myText" [(ngModel)]="myTextModel" name="myText" #myText="ngModel"&gt;
  &lt;/form&gt;
  &lt;button (click)="updateMyTextModel()"&gt;Update myTextModel&lt;/button&gt;
  &lt;div *ngIf="testForm.dirty"&gt;testForm diry&lt;/div&gt;
  &lt;div *ngIf="testForm.touched"&gt;testForm touched&lt;/div&gt;
  </code></pre>
  
  <p>How do I set the form touched or dirty from code?</p>
  
  <p>Note: In this example i use a button to trigger the model change, but i also might update the model in other ways, such as in a callback from an web api async request.</p>