0
Hello, I have an Angular System that requires a specific script!
This Component is not started on the first screen of my application, so I cannot put my script file in the Bundler, because by the Bundler this file is loaded only once it is the startup of the first compoenent that will be loaded. For example:
In my 3rd place I have an id input 'data', and in this jquery file I have an id called like this: $('#data'). When the bundler goes up this file, it goes up in the 1st Component only and when it arrives in the 3rd it does not load again, making it impossible to read my Id.
I wonder if there is a way to call this specific file only when my Component is called, so for example:
<script src="../../../../scripts/teste.js"></script>
<div class="container">
<p class="interest-preference">Escolha uma data e horário.</p>
<!--adjust Form Position-->
<div class="clear"></div>
<div class="wrap-input">
<input class="date-picker input.validator" id="datepicker" name="datepicker" type="text" placeholder="Data">
<label class="label-input" for="data">
<span class="far fa-calendar-alt"></span>
</label>
</div>
<div class="wrap-input">
<input class="timepicker" type="text" name="horario" id="horario" placeholder="Horário">
<label class="label-input" for="horario">
<span class="far fa-clock"></span>
</label>
</div>
<div class="wrap-input">
<div class="wrap-btn">
<button class="btn">
CONFIRMAR
</button>
</div>
</div>
</div>
Error presented
I can replace this link passed as a parameter by a local file path? for example: this.addJsToElement('.. /.. /.. /scripts/test.js')....
– Guilherme Nunes
tries to place the file inside the Assets folder
– Eduardo Vargas
and the way is the same way you use things from Assets normally "Assets/js/Myfile.js"
– Eduardo Vargas
I put the call in the method: 'ngOnInit()' and it didn’t work. put it this way: ngOnInit(): void { this.formulario = this.construirFormGroup(this.inputs); this.addJsToElement('../..../scripts/animacao.js'). onload = () => { console.log('Skyscanner Tag Loaded'); } }
– Guilherme Nunes
puts the script inside the Assets folder
– Eduardo Vargas
I put it on, and it still worked...
– Guilherme Nunes
Ta calling so this.addJsToElement('Assets/scripts/animacao.js')
– Eduardo Vargas
I edited my answer
– Eduardo Vargas
This answer link is presenting a walk online. a link. I need a physical path. I tried applying the path to the Assets folder and it still didn’t work. I will edit my question and add a photo showing the error shown.
– Guilherme Nunes
take a look at what I edited for Body.
– Eduardo Vargas
I get it, I’m gonna test
– Guilherme Nunes
i edited my code a look there at the penultimate line of the addJsToElement method.
– Eduardo Vargas
That worked 100% now. can insert as reply I give the like here, thank you
– Guilherme Nunes
What do you mean? I don’t understand.
– Eduardo Vargas