我不明白如何使用提供程序文件将点击按钮数据传递到另一个ts文件。
所以我想通过home.html控制4共享按钮,我试图通过home.html-> home.ts-> Popovershare.ts传递数据
多亏了poppvers,我在方形按钮内添加了一个共享按钮。
当我尝试直接向popovers.ts“ constructor(here)
”调用home函数时,出现了几个错误。
This is my home.html
<button icon-only (click)="click(1)">
<button icon-only (click)="click(2)">
<button icon-only (click)="click(3)">
<button icon-only (click)="click(4)">
This is my home.ts
click(myEvent) {
this.indexNumber = myEvent
let numbr_select
if (this.indexNumber == 1) {
numbr_select = 1
}
if (this.indexNumber == 2) {
numbr_select = 2
}
if (this.indexNumber == 3) {
numbr_select = 3
}
if (this.indexNumber == 4) {
numbr_select = 4
}
}
this.indexNumber = numbr_select
this.shareprovider.ValueFonction(this.indexNumber)
let popover = this.popoverCtrl.create(PopoversharePage, {
}, {
cssClass: 'csspopover'
});
popover.present({
ev: myEvent
});
}
这是我的shareprovider.ts
template: `
<ion-grid>
... share button with (click)="shareclick()"
</ion-grid>
constructor() {
this.ValueFonction()
}
ValueFonction(Number_selected?: any) {
for (let i = 1; i < 7; i++) {
if (Number_selected == i) {
// console.log(Number_selected, 'Valeur')
}
}
return Number_selected
}
这是我的Popovershare.ts
let i
for (let i = 0; i < 5; i++) {
switch (i) {
case 0:
this.ShareProvider.ValueFonction(1)
alert(1)
break;
case 1:
this.ShareProvider.ValueFonction(2)
alert(2)
break;
case 2:
this.ShareProvider.ValueFonction(3)
alert(3)
break;
case 3:
this.ShareProvider.ValueFonction(4)
alert(4)
break;
}
}
在这些代码中,它在控制台中显示我为每个按钮分配的编号,但是当我尝试使用此方法从popovers.ts调用到shareprovider.ts时
this.ShareProvider.ValueFonction(4) all alert run at the same time, i don't understand why.
我只想控制shareclick()
,但是此按钮在另一个文件ts中,希望您理解。
感谢您的关注!