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');

            }
        })  
    }
}
1

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.