Change image for individual users Angular 5
I have a array of users and i wish to be able to change the image associated with each individually
I have been able to do this on the profile users page no problem but can figure out how to do it when i have multiple profiles
<img [src]="member.person.imagePath"
(click)="fileInput.click()"
class="profile-image pointer img-fluid img-thumbnail">
<div style="text-align:center;"
class="cam-icon cam-pos"
[hidden]="!editing">
<i class="fa fa-camera pointer" (click)="fileInput.click()" aria-hidden="true"></i>
</div>
<input style="display: none"
type="file"
(change)="changeListener($event)"
#fileInput>
onFileChanged(event) {
const string = event.target.files[0]
this.currentUserData.familyMembers[0].person.imagePath = event.target.files[0];
}
changeListener($event) : void {
this.readThis($event.target);
}
readThis(inputValue: any): void {
var file:File = inputValue.files[0];
var myReader:FileReader = new FileReader();
myReader.onloadend = (e) => {
this.currentUserData.familyMembers[0].person.imagePath = myReader.result;
}
myReader.readAsDataURL(file);
}
currently i have it set to target the first member of the array just to check it was working and it does. my problem is targeting other members with a image uploaded from my computer
image typescript upload angular5
add a comment |
I have a array of users and i wish to be able to change the image associated with each individually
I have been able to do this on the profile users page no problem but can figure out how to do it when i have multiple profiles
<img [src]="member.person.imagePath"
(click)="fileInput.click()"
class="profile-image pointer img-fluid img-thumbnail">
<div style="text-align:center;"
class="cam-icon cam-pos"
[hidden]="!editing">
<i class="fa fa-camera pointer" (click)="fileInput.click()" aria-hidden="true"></i>
</div>
<input style="display: none"
type="file"
(change)="changeListener($event)"
#fileInput>
onFileChanged(event) {
const string = event.target.files[0]
this.currentUserData.familyMembers[0].person.imagePath = event.target.files[0];
}
changeListener($event) : void {
this.readThis($event.target);
}
readThis(inputValue: any): void {
var file:File = inputValue.files[0];
var myReader:FileReader = new FileReader();
myReader.onloadend = (e) => {
this.currentUserData.familyMembers[0].person.imagePath = myReader.result;
}
myReader.readAsDataURL(file);
}
currently i have it set to target the first member of the array just to check it was working and it does. my problem is targeting other members with a image uploaded from my computer
image typescript upload angular5
add a comment |
I have a array of users and i wish to be able to change the image associated with each individually
I have been able to do this on the profile users page no problem but can figure out how to do it when i have multiple profiles
<img [src]="member.person.imagePath"
(click)="fileInput.click()"
class="profile-image pointer img-fluid img-thumbnail">
<div style="text-align:center;"
class="cam-icon cam-pos"
[hidden]="!editing">
<i class="fa fa-camera pointer" (click)="fileInput.click()" aria-hidden="true"></i>
</div>
<input style="display: none"
type="file"
(change)="changeListener($event)"
#fileInput>
onFileChanged(event) {
const string = event.target.files[0]
this.currentUserData.familyMembers[0].person.imagePath = event.target.files[0];
}
changeListener($event) : void {
this.readThis($event.target);
}
readThis(inputValue: any): void {
var file:File = inputValue.files[0];
var myReader:FileReader = new FileReader();
myReader.onloadend = (e) => {
this.currentUserData.familyMembers[0].person.imagePath = myReader.result;
}
myReader.readAsDataURL(file);
}
currently i have it set to target the first member of the array just to check it was working and it does. my problem is targeting other members with a image uploaded from my computer
image typescript upload angular5
I have a array of users and i wish to be able to change the image associated with each individually
I have been able to do this on the profile users page no problem but can figure out how to do it when i have multiple profiles
<img [src]="member.person.imagePath"
(click)="fileInput.click()"
class="profile-image pointer img-fluid img-thumbnail">
<div style="text-align:center;"
class="cam-icon cam-pos"
[hidden]="!editing">
<i class="fa fa-camera pointer" (click)="fileInput.click()" aria-hidden="true"></i>
</div>
<input style="display: none"
type="file"
(change)="changeListener($event)"
#fileInput>
onFileChanged(event) {
const string = event.target.files[0]
this.currentUserData.familyMembers[0].person.imagePath = event.target.files[0];
}
changeListener($event) : void {
this.readThis($event.target);
}
readThis(inputValue: any): void {
var file:File = inputValue.files[0];
var myReader:FileReader = new FileReader();
myReader.onloadend = (e) => {
this.currentUserData.familyMembers[0].person.imagePath = myReader.result;
}
myReader.readAsDataURL(file);
}
currently i have it set to target the first member of the array just to check it was working and it does. my problem is targeting other members with a image uploaded from my computer
image typescript upload angular5
image typescript upload angular5
asked Nov 23 '18 at 20:12
Aidan WardAidan Ward
327
327
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
So instead of using [0] as the element, you need to pass the index back with the change function.
So wherever you do your *ngFor loop, add index like so:
<ng-container *ngFor="let member of members; let i = index;">
<img [src]="member.person.imagePath"
(click)="fileInput.click()"
class="profile-image pointer img-fluid img-thumbnail">
<div style="text-align:center;"
class="cam-icon cam-pos"
[hidden]="!editing">
<i class="fa fa-camera pointer" (click)="fileInput.click()" aria-hidden="true"></i>
</div>
<input style="display: none"
type="file"
(change)="changeListener($event, i)"
#fileInput>
</ng-container>
changeListener($event, index: number) : void {
this.readThis($event.target, index);
}
readThis(inputValue: any, index: number): void {
var file:File = inputValue.files[0];
var myReader:FileReader = new FileReader();
myReader.onloadend = (e) => {
this.currentUserData.familyMembers[index].person.imagePath = myReader.result;
}
myReader.readAsDataURL(file);
}
Yes buddy brilliant. Such a easy solution. Thanks a lot
– Aidan Ward
Nov 26 '18 at 13:18
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53452466%2fchange-image-for-individual-users-angular-5%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
So instead of using [0] as the element, you need to pass the index back with the change function.
So wherever you do your *ngFor loop, add index like so:
<ng-container *ngFor="let member of members; let i = index;">
<img [src]="member.person.imagePath"
(click)="fileInput.click()"
class="profile-image pointer img-fluid img-thumbnail">
<div style="text-align:center;"
class="cam-icon cam-pos"
[hidden]="!editing">
<i class="fa fa-camera pointer" (click)="fileInput.click()" aria-hidden="true"></i>
</div>
<input style="display: none"
type="file"
(change)="changeListener($event, i)"
#fileInput>
</ng-container>
changeListener($event, index: number) : void {
this.readThis($event.target, index);
}
readThis(inputValue: any, index: number): void {
var file:File = inputValue.files[0];
var myReader:FileReader = new FileReader();
myReader.onloadend = (e) => {
this.currentUserData.familyMembers[index].person.imagePath = myReader.result;
}
myReader.readAsDataURL(file);
}
Yes buddy brilliant. Such a easy solution. Thanks a lot
– Aidan Ward
Nov 26 '18 at 13:18
add a comment |
So instead of using [0] as the element, you need to pass the index back with the change function.
So wherever you do your *ngFor loop, add index like so:
<ng-container *ngFor="let member of members; let i = index;">
<img [src]="member.person.imagePath"
(click)="fileInput.click()"
class="profile-image pointer img-fluid img-thumbnail">
<div style="text-align:center;"
class="cam-icon cam-pos"
[hidden]="!editing">
<i class="fa fa-camera pointer" (click)="fileInput.click()" aria-hidden="true"></i>
</div>
<input style="display: none"
type="file"
(change)="changeListener($event, i)"
#fileInput>
</ng-container>
changeListener($event, index: number) : void {
this.readThis($event.target, index);
}
readThis(inputValue: any, index: number): void {
var file:File = inputValue.files[0];
var myReader:FileReader = new FileReader();
myReader.onloadend = (e) => {
this.currentUserData.familyMembers[index].person.imagePath = myReader.result;
}
myReader.readAsDataURL(file);
}
Yes buddy brilliant. Such a easy solution. Thanks a lot
– Aidan Ward
Nov 26 '18 at 13:18
add a comment |
So instead of using [0] as the element, you need to pass the index back with the change function.
So wherever you do your *ngFor loop, add index like so:
<ng-container *ngFor="let member of members; let i = index;">
<img [src]="member.person.imagePath"
(click)="fileInput.click()"
class="profile-image pointer img-fluid img-thumbnail">
<div style="text-align:center;"
class="cam-icon cam-pos"
[hidden]="!editing">
<i class="fa fa-camera pointer" (click)="fileInput.click()" aria-hidden="true"></i>
</div>
<input style="display: none"
type="file"
(change)="changeListener($event, i)"
#fileInput>
</ng-container>
changeListener($event, index: number) : void {
this.readThis($event.target, index);
}
readThis(inputValue: any, index: number): void {
var file:File = inputValue.files[0];
var myReader:FileReader = new FileReader();
myReader.onloadend = (e) => {
this.currentUserData.familyMembers[index].person.imagePath = myReader.result;
}
myReader.readAsDataURL(file);
}
So instead of using [0] as the element, you need to pass the index back with the change function.
So wherever you do your *ngFor loop, add index like so:
<ng-container *ngFor="let member of members; let i = index;">
<img [src]="member.person.imagePath"
(click)="fileInput.click()"
class="profile-image pointer img-fluid img-thumbnail">
<div style="text-align:center;"
class="cam-icon cam-pos"
[hidden]="!editing">
<i class="fa fa-camera pointer" (click)="fileInput.click()" aria-hidden="true"></i>
</div>
<input style="display: none"
type="file"
(change)="changeListener($event, i)"
#fileInput>
</ng-container>
changeListener($event, index: number) : void {
this.readThis($event.target, index);
}
readThis(inputValue: any, index: number): void {
var file:File = inputValue.files[0];
var myReader:FileReader = new FileReader();
myReader.onloadend = (e) => {
this.currentUserData.familyMembers[index].person.imagePath = myReader.result;
}
myReader.readAsDataURL(file);
}
answered Nov 24 '18 at 4:51
user1779362user1779362
387213
387213
Yes buddy brilliant. Such a easy solution. Thanks a lot
– Aidan Ward
Nov 26 '18 at 13:18
add a comment |
Yes buddy brilliant. Such a easy solution. Thanks a lot
– Aidan Ward
Nov 26 '18 at 13:18
Yes buddy brilliant. Such a easy solution. Thanks a lot
– Aidan Ward
Nov 26 '18 at 13:18
Yes buddy brilliant. Such a easy solution. Thanks a lot
– Aidan Ward
Nov 26 '18 at 13:18
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53452466%2fchange-image-for-individual-users-angular-5%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown