我试图制作一个简单的Angular表单来上传用户输入。其中一个步骤涉及选择图像。在将图像上传到服务器之前,我尝试从远程源获取图像。
app.controller('submissionFormController', function ($http) {
this.formIsVisible = false;
...
this.sub = { //this Object contains the data entered into the form
};
this.uploadImage = function(img){
this.sub.imgfile = img;
};
this.downloadImage = function () {
url = this.sub.imgurl;
var filename = url.substring(url.lastIndexOf("/") + 1).split("?")[0];
var xhr = new XMLHttpRequest();
xhr.responseType = 'blob';
xhr.onload = function () {
this.uploadImage(xhr.response);
console.log("Image fetched!");
};
xhr.open('GET', url);
xhr.send();
};
});
执行代码时,出现以下错误:
Object doesn't support property or method 'uploadImage'
答案 0 :(得分:0)