Uncaught Referenceerror: vira1 is not defined

Asked

Viewed 424 times

0

I’m creating a function but when it’s called it says it hasn’t been defined yet, what would be the reason ?

import { Component } from '@angular/core';
import { NavController, NavParams } from 'ionic-angular';

@Component({
  selector: 'page-jogomemoria',
  templateUrl: 'jogomemoria.html',
})
export class JogomemoriaPage {

  constructor(public navCtrl: NavController, public navParams: NavParams) {
  }

 
}
function vira1(){
	document.getElementById("vira0").style.zIndex = "999";
}
<ion-header>
</ion-header>


<ion-content padding class="bgcMemoria">
  <div class="fase1">
    <div class="viradasBaixo">
      <img src="assets/img/carta.jpg" id="viradaBaixo1" onclick="vira1()">
    </div>
    <div class="viradasCima" id="viradasCima">
      <img src="assets/img/virada.jpg" id="vira0"></img>
    </div>
  </div>
</ion-content>

  • 1

    Instead of onclick= utilize (click)=

1 answer

1


From the Angular 2 to make Binding of events are used parentheses, every time you want to call an event do (evento)="exeFuncao()"

Some events:

(focus)="exeFuncao()"
(blur)="exeFuncao()"

(submit)="exeFuncao()"

(scroll)="exeFuncao()"

(cut)="exeFuncao()"
(copy)="exeFuncao()"
(paste)="exeFuncao()"

(keydown)="exeFuncao()"
(keypress)="exeFuncao()"
(keyup)="exeFuncao()"

(mouseenter)="exeFuncao()"
(mousedown)="exeFuncao()"
(mouseup)="exeFuncao()"

(click)="exeFuncao()"
(dblclick)="exeFuncao()"

(drag)="exeFuncao()"
(dragover)="exeFuncao()"
(drop)="exeFuncao()"

You can see the complete list in this article on the site of Mozilla.

Another mistake is that your method vira1 is out of class JogomemoriaPage then it won’t work.

import { Component } from '@angular/core';
import { NavController, NavParams } from 'ionic-angular';

@Component({
    selector: 'page-jogomemoria',
    templateUrl: 'jogomemoria.html',
})
export class JogomemoriaPage {
    constructor(public navCtrl: NavController, public navParams: NavParams) {
    }
    vira1(){
        document.getElementById("vira0").style.zIndex = "999";
    }
}
  • And to declare a variable in ? I’m trying but it keeps giving error would not be like this ? "Let variable: any = 0;" is showing error in Let

  • What variable? Because the question does not have, there is another problem, I recommend opening another question, because I will have to signal as broad. When creating a question make sure you have put all the details.

  • I opened another question with more details

  • But try to put the variable in the method constructor without the let.

  • Right, now if the answer has solved this problem consider ticking as accepted.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.