I'm writing an angular2 component. In this component i have 3 inputs. I paste a variable to each of the inputs. Is it possible to paste inputs by reference?
I want to be able to paste variable to a component and once I change it's value, I want the change to be reflected on the variable outside of that component. Which means passing the variables by reference. Is it possible in angular 2? I know that I can subscribe to events. And fire an event apon change. I'm wondering if there is a simpler solution.
Any information regarding the issue would be greatly appreciated
update
this is the code for the component that 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. now I use that component in the following way:
<image-upload [imageUrl]="imageUrl" [imageFile]="imageFile" [imageRotateDegrees]="imageRotateDegrees"></image-upload>
here I'm passing 3 variables to the component.
and the component understands those variables from the input definition.
now.. what I want is to be able to change the variables inside the component, and that they will be changed outside the component. as I understand the variables are pasted by value and not by reference.
so what do i do?