Como exigir uma função como parâmetro em typescript

Multi tool use
Multi tool use
The name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP


Como exigir uma função como parâmetro em typescript



Quero generalizar em um serviço uma função de criar popups do Ionic 3



aqui está o serviço


`import { HttpClient } from '@angular/common/http';
import { Injectable } from '@angular/core';
import { AlertController, ToastController } from 'ionic-angular';

export interface button {
text: string,
handler: any // function
}


@Injectable()
export class MessagesProvider {

constructor(
public http: HttpClient,
public alertCtrl: AlertController,
public toastCtrl: ToastController,
) { }

popupCreator(title: string, message: string, buttons: button) {
return this.alertCtrl.create({
title: title,
message: message,
buttons: buttons
}).present()
}

showToast(text:string, position:string , duration?:number) {
return this.toastCtrl.create({
message: text,
duration: duration ? duration : 3000,
position: position
}).present();
}

}`



essa é a função original


`this.alertCtrl.create({
title: 'Texto',
message: 'mensagem',
buttons: [{
text: 'CANCELAR',
handler: () => { }
},
{
text: 'OK',
handler: () => { funcaoParametro(); }
}
]
})present();`



então o que eu estou tentando fazer é obrigar quem usar o serviço a enviar um objeto no formato correto de buttons que executaria a função parâmetro desejada.



Isso é possível?





This site is in English. Either you want Stack Overflow en español or Stack Overflow em Português.
– Some programmer dude
10 secs ago











By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

02xUKTFz
wCKt8f gwjudzpNyyI5U D XCSh MM5aG2vnKOLu ncDn

Popular posts from this blog

Keycloak server returning user_not_found error when user is already imported with LDAP

PHP parse/syntax errors; and how to solve them?

Using generate_series in ecto and passing a value