In my child component, I have a property named files
, which is an input type=file
. This property allows me to determine if the user has selected a file for upload so that I can disable the submit button if no files are present in the input field. The issue I'm facing now is that the submit button is located in the parent component, making it challenging to access the files
property to enable the button when a file is selected.
Is there a way for me to access the files
property from the parent component and check if a file is present in the input field?
I've attempted using the @ViewChild
decorator with something like this.childComponent.files
, but I keep getting 'undefined'. I also tried using @Output
without success.
Added code:
Parent Component TypeScript:
(Code example same as above)
Parent Component HTML:
(Code example same as above)
Children Component TypeScript:
(Code example same as above)
Children Component HTML:
(Code example same as above)
Edit #2:
html parent:
<app-step-one #StepOneComponent></app-step-one>
ts parent:
(Code example same as above)
ts child added:
(Code example same as above)
I also tried this.stepOneComponent.files;
, but it did not work. However, creating a getFiles()
function in the child component allowed me to retrieve the file data successfully. My goal now is to automatically detect changes instead of relying on a manual function triggered by a button click.
Edit #3 (for duplicate):
The solution provided in another question does not suit my needs as I require automatic change detection rather than manual intervention.