I'm trying to upload and display image inside ng-repeat.
I've succeeded to upload and display image without ng-repeat using jquery function:
<html>
<head>
<script src="jquery.js" type="text/javascript"></script>
</head>
<body>
<input type='file' />
<img id="myImg" ng-src="#" alt="your image" style="width:50px;height:50px"/>
</body>
</html>
...
<script>
$(function () {
$(":file").change(function () {
if (this.files && this.files[0]) {
var reader = new FileReader();
reader.onload = imageIsLoaded;
reader.readAsDataURL(this.files[0]);
}
});
});
function imageIsLoaded(e) {
$('#myImg').attr('src', e.target.result);
};
</script>
if i change the code to be inside ng-repeat, the jQuery function dosent work:
<div ng-repeat="step in stepsModel">
<input type='file' />
<img id="myImg" ng-src="#" alt="your image" style="width:50px;height:50px"/>
/div>
2 questions:
- how can i change the jquery function to angular function?
- how can i make the ng-reapeat deal with the jquery function?
Many thanks