I am writing an angular2 component. In this component I have 3 inputs. I insert a variable into each of the inputs. Can I insert inputs by reference?
I want to be able to insert a variable into a component, and as soon as I change its value, I want the change to reflect on the variable outside this component. This means passing variables by reference. Is this possible in angular 2? I know that I can subscribe to events. And fire changes events. I am wondering if there is a simpler solution.
Any information regarding this issue would be greatly appreciated.
Update
This is the code for the component I created.
import { Component } from '@angular/core';
import {MdButton} from '@angular2-material/button';
import {ImageRotation} from './image-rotation';
import {FileReaderEvent} from './file-reader-event';
@Component({
selector: 'image-upload',
templateUrl: '/client/imports/components/image-upload/image-upload.html',
directives: [MdButton],
inputs: ['imageUrl','imageFile','imageRotateDegrees']
})
export class ImageUploadComponent {
imageRotationObj:ImageRotation;
imageUrl:string;
imageSrc:any;
imageFile: any;
imageRotateDegrees:number;
imageExifRotation:number;
isImageFileExif:boolean;
imageChanged() {
var reader = new FileReader();
reader.onload = (e:FileReaderEvent)=> {
var exif = EXIF.readFromBinaryFile(e.target.result);
switch (exif.Orientation) {
case 8:
this.imageRotateDegrees=-90;
this.imageExifRotation=-90;
this.isImageFileExif=true;
this.imageRotationObj.setImageRotation(-90);
break;
case 3:
this.imageRotateDegrees=180;
this.imageExifRotation=180;
this.isImageFileExif=true;
this.imageRotationObj.setImageRotation(180);
break;
case 6:
this.isImageFileExif=true;
this.imageExifRotation=90;
this.imageRotateDegrees=90;
this.imageRotationObj.setImageRotation(90);
break;
default:
this.isImageFileExif=false;
}
};
var reader2 = new FileReader();
reader2.onload = (e:FileReaderEvent)=> {
this.imageSrc=e.target.result;
}
reader.readAsArrayBuffer(this.imageFile);
reader2.readAsDataURL(this.imageFile);
}
constructor() {
this.imageRotationObj=new ImageRotation();
}
fileOnChange(event:any) {
this.imageFile = event.target.files[0];
this.imageChanged();
}
}
as you can see, I defined 3 inputs. I now use this component as follows:
<image-upload [imageUrl]="imageUrl" [imageFile]="imageFile" [imageRotateDegrees]="imageRotateDegrees"></image-upload>
here I pass 3 variables to the component.
.
.. , . , , .
?