html:
<input name="image" id="image" type="file" value="" multiple accept="image/*" ng-model="imagePath" ng-change="editPic()" />
controller:
$scope.editPic = function(){
console.log(1);
};
我想在选择图片后,触发一个事件,为什么这样不会触发controller里的事件?谢谢。
我这里有一个 angular 中 input type="file" 的指令,用法是 <input type="file" file-read="uploadMe" />
coffeeScript的格式,自己转换成JS就好
angular.module "ws.fileRead", []
.directive "fileRead", [
->
scope:
fileRead: "="
link: (scope, element, attributes)->
element.bind "change", (changeEvent)->
reader = new FileReader()
reader.onload = (loadEvent)->
scope.$apply ->
scope.fileread = loadEvent.target.result
return
return
]
你可以试试ng-file-upload,很强大
首先,请把代码贴完整;
其次,你这里只是绑定了input的change事件,跟图片有啥关系??