[英]AngularJS send image to directive (and show directive)
我認為我要綁定文件上傳,因此:
<input type="file" name="file" onchange="angular.element(this).scope().photoChanged(this.files)"/>
我有這樣的指令:
.directive('imageCrop', function () {
return {
template: '<div style="display: none;"><p>Image!</p></div>',
restrict: 'E',
link: function postLink(scope, element, attrs) {
element.text('this is the imageCrop directive');
}
};
});
我如何在控制器的方法中使此指令可見並將其圖像發送給它?
在這種情況下哪種做法最好?
將ngModel
注入您的指令,例如
<input type="file" name="file" onchange="angular.element(this).scope().photoChanged(this.files)"/>
<imageCrop ngModel="image" />
在您的photoChanged
函數中,將上傳的文件綁定到模型image
。 此外,在指令定義中需要ngModel
。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.