title: Convert an Image to byte array in Angular (typescript)
body: <p>I have a requirement where I need to convert the selected image (a part of a form group) to a byte array which needs to be sent as a part of a post request to the backend.</p>
  <p>HTML Component:</p>
  <pre><code>&lt;div class=&quot;form-group&quot;&gt;
                  &lt;label&gt;Image&lt;/label&gt;
                  &lt;input type=&quot;file&quot; accept=&quot;image/*&quot; class=&quot;form-control&quot; formControlName=&quot;productImage&quot; onchange=&quot;displaySelectedImageFunc(this);&quot;&gt;
                  &lt;img *ngIf=&quot;displaySelectedImage&quot; src=&quot;{{selectedImageUrl}}&quot;&gt;
                  &lt;span class=&quot;error-message&quot; *ngIf=&quot;itemRegistrationForm.controls.productImage.dirty &amp;&amp; itemRegistrationForm.controls.productImage.errors&quot;&gt;Select Image of the product&lt;/span&gt;
  &lt;/div&gt;
  </code></pre>