I'm very new to Angular. I'm trying to make a simple web application using Angular 2 where I allow the users to select and image from their local computer. Then I want to display this image in an <img>
tag. Later perform actions on the image like rotate, change scale, change width...etc.
This is what I have in my component
@Component({
selector: 'image-container',
template: `
<input type="file" (change)="changeListner($event)" />
<img id="image"/>
`,
directives: [ImageActionsComponent]
})
export class ImageContainerComponent {
// make FileReader work with Angular2
changeListner(event){
var reader = new FileReader();
reader.onloaded = function (e) {
// get loaded data and render thumbnail.
var src = e.target.result;
document.getElementById("image").src = src;
};
// read the image file as a data URL.
reader.readAsDataURL(event.target.files[0]);
}
}
But it doesn't work at all. How do I read an image and update the src attribute using Angular2?
I'm just trying to learn Angular. :)
Is there a better and easier way to do this?