Incluse Javascript file(corrected)

Sorry, I made a bad post. I publish the corrected poste:

Hello every Body. I have creat a little script for test something.
I search a solution regarding the inclusion a Js file.


const btn = document.querySelector(“ion-button”);
const fruits = [“banane”, “cerise”, “orange”, “raisin”, “ananas”];
const result = document.querySelector(".result");

function random(){
let fruit_random = Math.round(Math.random()*(fruits.length-1));
result.innerHTML = fruits[fruit_random]

btn.addEventListener(“click”, random); //bad


  <ion-toolbar class="head_fond">
    <ion-buttons slot="start">
      <ion-back-button defaultHref="/tab1" text="tab 1"></ion-back-button>
    <ion-title>Fruit aléatoire</ion-title>
<ion-content class="fond">
  <ion-label classe="label1">Veuillez cliquer sur le bouton</ion-label><br>
  <ion-button id="ion-button" class="button">
    <ion-label class="label_button">Salut</ion-label>
  <ion-label classe="label2">résultat</ion-label><br>
  <ion-label class="result"></ion-label>
  <script src="script.js"></script>


the scipt works if it is in "ngOnInit () {

}; " of sociale.ts


Emulate the Tour of Heroes.

And to add to it - you cannot do this in an angular template. While it has extension html, it actually isn’t html. The only true html in an angular app is is to be found in index.html.

Understanding angular through the ToH recommendation by @rapropos is recommendable after which you may want to redefine your need.