R
R
risich32017-04-30 20:15:15
Angular
risich3, 2017-04-30 20:15:15

How to upload an image in Angular 2?

It is necessary to implement the loading of images in the application on the second angular. How can this be implemented?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
P
planc, 2017-04-30
@planc

since no one answers, I don’t really remember angular
like this in vue, do it by analogy:

<form>
      <div class="form-group">
        <label for="InputFile">File input</label>
        <input type="file" id="InputFile" @change="onFileChange">
        <p class="help-block">Upload image</p>
      </div>
    </form>

onFileChange (e) {
      let file = e.target.files[0] || e.dataTransfer.files[0]
      let formData = new FormData()
      formData.append('image', file)
      this.$http.post('upload/', formData)
        .then(response => {
          console.log(response)
        }, error => {
          console.log(error)
        })
    }

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question