Quantcast
Channel: Ionic Framework - Ionic Forum
Viewing all articles
Browse latest Browse all 48980

Incluse Javascript file(corrected)

$
0
0

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.

Javascript

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));
console.log(fruits[fruit_random])
result.innerHTML = fruits[fruit_random]

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

html:

<ion-header>
  <ion-toolbar class="head_fond">
    <ion-buttons slot="start">
      <ion-back-button defaultHref="/tab1" text="tab 1"></ion-back-button>
    </ion-buttons>
    <ion-title>Fruit aléatoire</ion-title>
   
  </ion-toolbar>
</ion-header>
  
<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-button><br>
  <ion-label classe="label2">résultat</ion-label><br>
  <ion-label class="result"></ion-label>
  <script src="script.js"></script>

</ion-content>

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

}; " of sociale.ts

Capture

3 posts - 3 participants

Read full topic


Viewing all articles
Browse latest Browse all 48980

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>