1

I am trying to upload image but i am not sure with my method, how can i append my image in template to console? Can someone suggest how to please?

My template:

<input type="file" ng2FileSelect [uploader]="uploader" />

My component:

   import {Component} from '@angular/core';
   import {Http, Response, Headers} from '@angular/http';
   import {FILE_UPLOAD_DIRECTIVES, FileUploader} from '../ng2-file-upload/ng2-file-upload';
 const URL = 'http://localhost/a2server/index.php/profile/upload';
 @Component({
    selector:'Professional',
    templateUrl:'./components/professional/professional.html',
    directives: [FILE_UPLOAD_DIRECTIVES]
 })

  export class Professional{


     constructor(public http: Http){
     var uploader:FileUploader;
       var headers = new Headers();
       headers.append('Content-Type', 'application/x-www-form-urlencoded')
    // var str = localStorage.getItem('social');
    // var loc = JSON.parse(str);
    // var id = loc.profile_id;
         this.http.post('http://localhost/a2server/index.php/profile/upload', uploader, { headers: headers })
        .subscribe(
        response => {
            if (response.json().error_code == 0) {
              alert('success');
            }
            else {
              alert('fail');

            }
        })  
    }
}
Günter Zöchbauer
  • 623,577
  • 216
  • 2,003
  • 1,567
MMR
  • 2,869
  • 13
  • 56
  • 110
  • dup of http://stackoverflow.com/questions/37807133/upload-file-angular-2, http://stackoverflow.com/questions/35985347/how-to-upload-file-in-angular2 ? – Günter Zöchbauer Aug 19 '16 at 07:28

0 Answers0