title: How to upload file in Angular2
body: <p>I have to submit a form along with image. i have tried this code (with multiple ways) but did't work for me. is there anyone having working demo of file uploading using angular2 please help me out.</p>
  
  <p>component.html</p>
  
  <pre><code>    &lt;form class="form-horizontal" role="form" &gt;
  
          &lt;div class="form-group"&gt;
              &lt;label class="control-label col-sm-4" for="myname" style=""&gt;Name&lt;span class="asterisk"&gt;*&lt;/span&gt;&lt;/label&gt;
              &lt;div class="col-sm-7"&gt;
                  &lt;div&gt;
                      &lt;input type="text" class="form-control" id="myname"
                      [(ngModel)]="myfile.name"&gt;                        
                  &lt;/div&gt;                  
              &lt;/div&gt;                               
          &lt;/div&gt;        
  
  
          &lt;div class="form-group"&gt;
              &lt;label class="control-label col-sm-4" for="myimage"&gt;Image&lt;/label&gt;
              &lt;div class="col-sm-7"&gt;
                  &lt;div&gt;
                      &lt;input type="file" (change)="fileChangeEvent($event)" placeholder="Upload file..." /&gt;                         
                  &lt;/div&gt;   
              &lt;/div&gt;
          &lt;/div&gt;
  
  
          &lt;div class="form-group"&gt;        
          &lt;div class="text-center"&gt;
              &lt;button type="button" (click)="upload()"&gt;Upload&lt;/button&gt;             
          &lt;/div&gt;
          &lt;/div&gt;
    &lt;/form&gt;
  </code></pre>
  
  <p>component.ts</p>
  
  <pre><code>     myfile={
                  "name":"Mubashshir",               
                  "image":''
       }
  
       fileChangeEvent(fileInput: any){
          this.myfile.image = fileInput.target.files;        
       }
  
       upload(){
            this.base_path_service.PostRequest('http://128.199.190.109/api/school/schoolDetail/',this.myfile)
              .subscribe(
                  data =&gt; {
                              console.log("data submitted");                        
                          },
                  err =&gt; console.log(err),
                  () =&gt;{
                       console.log('Authentication Complete');                    
  
                  }
              );
        }
  </code></pre>