title: How to post a form in angular 2 with image to upload
body: <p>Note:
   I am already using .net web api , it's working fine with postman.
  Like:</p>
  
  <pre><code>public HttpResponseMessage FormPost()
              {
      string member_f_name = HttpContext.Current.Request.Form["member_name"];
      if (HttpContext.Current.Request.Files.Count &gt; 0)
                      {
  
                          myfiles = HttpContext.Current.Request.Files[0];
                          if (myfiles == null)
                              retmsg = "Comment Post Successfully.";
                          else
                          {
                              if (myfiles.ContentLength &gt; 0)
                                  retmsg = "Image Uploaded successfully.";
                              else
                                  retmsg = "Comment Post Successfully.";
                          }
                      }
  }
  </code></pre>
  
  <p>I only want to post file(image) with text-box text.
  With same api code.
  I am already used two separate code from angular.
  1.for file upload(but it's uploading file on file change)
  2.And one is for submitting data on-click of submit button.</p>
  
  <p>Code Snippt for file upload.</p>
  
  <pre><code>fileChange(event) {
          debugger;
  
      let fileList: FileList = event.target.files;
      if(fileList.length &gt; 0) {
          let file: File = fileList[0];
          let formData:FormData = new FormData();
          formData.append('file', file, file.name);
          let headers = new Headers({'Access-Control-Allow-Origin': '*'} );
          headers.append('enctype', 'multipart/form-data');  
          headers.append('Accept', 'application/json');  
          let method="post";
          let options = new RequestOptions({ headers: headers }); 
          let apiUrl1 = "http://local:port/api/Controller/Action";  
          this.http.post(apiUrl1, formData, options)  
         .map(res =&gt; res.json())  
          .catch(error =&gt; Observable.throw(error))  
          .subscribe(  
          data =&gt; console.log('success'),  
          error =&gt; console.log(error)  
          )  
  
  
      }
  }
  </code></pre>
  
  <p>Another for submitting all data with form.</p>
  
  <pre><code>submitForm(myForm:NgForm) {
    debugger;
  
    var objFormData = new FormData();
                  for (var key in myForm.value)
                      objFormData.append(key, myForm.value[key]);
                    let headers = new Headers({'Access-Control-Allow-Origin': '*'} );
          headers.append('enctype', 'multipart/form-data');  
          headers.append('Accept', 'application/json');  
            let options = new RequestOptions({ headers: headers }); 
  // this.adminRegister.register(objFormData);
   let apiUrl1 = "http://localhost:port/api/Controller/Action";  
     this.http.post(apiUrl1, objFormData, options)  
         .map(res =&gt; res.json())  
      .catch(error =&gt; Observable.throw(error))  
      .subscribe(  
      data =&gt; console.log('success'),  
      error =&gt; console.log(error)  
      )  
  
   }
  </code></pre>