2
我目前停留在一種情況和情況是我想綁定指令到我的HTML,但沒有任何作品我想要綁定指令範圍與HTML 這是我在做什麼:綁定指令屬性到控制器不工作
這是我的指令,我想要的是屬性文件綁定到我的HTML,所以我可以得到文件和修改日期的名稱
.directive("fileinput", [function() {
return {
scope: {
file: "=",
filepreview: "="
},
link: function(scope, element, attributes) {
element.bind("change", function(changeEvent) {
scope.file = changeEvent.target.files[0];
scope.filepreview='';
var reader = new FileReader();
reader.onload = function(loadEvent) {
scope.$apply(function() {
console.log(scope.file)//printing file value but not reflect in html
scope.filepreview = loadEvent.target.result;
var ctx = document.getElementById('myCanvas').getContext('2d');
ctx.clearRect(0, 0, 300, 130);
var img = new Image();
img.src = scope.filepreview ;
img.onload = function() {
ctx.drawImage(img, 0, 0);
}
});
}
reader.readAsDataURL(scope.fileinput);
});
}
}
}])
的index.html
<div class='form-group required'>
<label>{{file.LastModified}}</label>
<input type="file" fileinput="file" filepreview="filepreview"/>
</div>
當我上傳文件,但在指令中,我得到的文件 任何幫助將不勝感激,沒有任何反應。