I have a requirement where I have load multiple items using item list. Whenever you upload a file, upload file input has to hide and details of that file has to show like filename and other button.
I implemented the scenario by using a localvariable, it works fine with one item, but when we have multiple items, its not working. Assume if I have 3 itemList, if we click on 1st item fileupload button and upload a file, it loads filename and validate button, but if we do same process for 2nd item (after 1st process), after fileupload, 1st filename will be modified.
View:
<div id="userItemList" *ngFor="let item of itemList; let i=index">
<div>
<span>{{item.Id}}</span>
<span>{{item.Name}}</span>
<span>{{item.Count}}</span>
</div>
<div>
<input type="file" name="UploadFile" id="fileInput" #fileInput (change)="txtUploadFile($event,i)">
<div class="validate-file-div" #validateContent style="display:none">
<div class="file-name" #fileName></div>
<span id="validate-csv-button" data-program-id="0" class="button">Validate</span>
</div>
</div>
</div>
My component look like:
import { Component, OnInit, ViewChild } from '@angular/core';
@Component({
selector: 'app-programs-manager',
templateUrl: './ProgramsManager.component.html',
styleUrls: ['./ProgramsManager.component.css'],
})
export class ProgramsManagerComponent implements OnInit {
itemList = [{"Id":1,"Name":"Item1","Count":2},{"Id":2,"Name":"Item2","Count":2},{"Id":3,"Name":"Item3","Count":3}];
@ViewChild("fileInput") fileInput;
@ViewChild("validateContent") validateContent;
@ViewChild("fileName") fileName;
constructor() { }
ngOnInit() {
}
txtUploadFile(event,index) {
this.fileInput.nativeElement.style.display = "none";
this.validateContent.nativeElement.style.display = "block";
this.fileInput.nativeElement.innerHTML = event.target.files[0].name;
}
}
I feel local variable is giving problem,but don't know how to fix it. can anyone help me. Thanks in advance