Good afternoon guys, this is my first post here on stackoverflow so I apologize if there is any error ..
My question is this: I'm working with Ionic and I need to "get" the day of the week and turn it into a number to be able to work with conditionals for this value, so there is the getDay () method that returns a value of 0 to 6 .. so far, okay! When I put it inside the constructor like the print below:
The function returns the value normally !!! No running errors
Now, when I try to create a function outside of the constructor, calling the getDay () method, like this:
InthehtmlpartIput(click)="refresh ()" on a button to pass the value returned by getDay to the variable day, gives an error saying that "getDay ()" is not a function. Why does not the builder work, and not out?
@edit .ts code:
import { Component } from '@angular/core';
import { IonicPage, NavController, NavParams } from 'ionic-angular';
import { DatePicker } from '@ionic-native/date-picker';
/**
* Generated class for the AdicionaPage page.
*
* See https://ionicframework.com/docs/components/#navigation for more info on
* Ionic pages and navigation.
*/
@Component({
selector: 'page-adiciona',
templateUrl: 'adiciona.html',
})
export class AdicionaPage {
today = new Date();
semana = ["Dom", "Seg", "Ter", "Qua", "Qui", "Sex", "Sáb"]
listaDia = Array;
listaMes = Array;
dia;
mes;
constructor(public navCtrl: NavController, public navParams: NavParams) {
}
ionViewDidLoad() {
console.log('ionViewDidLoad AdicionaPage');
}
refresh(){
this.dia = this.semana[this.today.getDate()];
}
}
<!--
Generated template for the AdicionaPage page.
See http://ionicframework.com/docs/components/#navigation for more info on
Ionic pages and navigation.
-->
<ion-header>
<ion-navbar>
<ion-title>Adiciona</ion-title>
</ion-navbar>
</ion-header>
<ion-content padding>
<ion-list>
<h2>Paciente</h2>
<ion-item>
<ion-input type="text" placeholder="Nome"></ion-input>
</ion-item>
<button clear ion-button>
<ion-item>
<ion-datetime placeholder="Data" displayFormat="DD MMM de YYYY" min="2018" [(ngModel)]="today"></ion-datetime>
</ion-item>
{{dia}}
</button>
</ion-list>
<button ion-button large color="secondary" class="botao" (click)="refresh()">
Salvar
</button>
</ion-content>