Change image for individual users Angular 5












0















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










share|improve this question



























    0















    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










    share|improve this question

























      0












      0








      0








      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










      share|improve this question














      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






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Nov 23 '18 at 20:12









      Aidan WardAidan Ward

      327




      327
























          1 Answer
          1






          active

          oldest

          votes


















          1














          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);
          }





          share|improve this answer
























          • Yes buddy brilliant. Such a easy solution. Thanks a lot

            – Aidan Ward
            Nov 26 '18 at 13:18











          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
          });


          }
          });














          draft saved

          draft discarded


















          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









          1














          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);
          }





          share|improve this answer
























          • Yes buddy brilliant. Such a easy solution. Thanks a lot

            – Aidan Ward
            Nov 26 '18 at 13:18
















          1














          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);
          }





          share|improve this answer
























          • Yes buddy brilliant. Such a easy solution. Thanks a lot

            – Aidan Ward
            Nov 26 '18 at 13:18














          1












          1








          1







          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);
          }





          share|improve this answer













          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);
          }






          share|improve this answer












          share|improve this answer



          share|improve this answer










          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



















          • 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




















          draft saved

          draft discarded




















































          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.




          draft saved


          draft discarded














          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





















































          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







          Popular posts from this blog

          404 Error Contact Form 7 ajax form submitting

          How to know if a Active Directory user can login interactively

          TypeError: fit_transform() missing 1 required positional argument: 'X'