Reputation: 340
I'm VERY new to Ionic/Angular/Typescript...
I have the following button:
<button ion-button (click)="shareMe('hello')">Hello</button>
<button ion-button (click)="shareMe('world')">World</button>
And I have the following function:
shareMe(){
this.sharingVar.share($STRING)
.then(()=>{
alert("Success");
},
()=>{
alert("failed");
})
};
Basically, when I click a given button, I want to pass a VARIABLE to the function to process. The code above obviously doesn't work... but how do you do this in Angular/Typescript?
Is there a way to pass a variable $string to a function?
Please be as descriptive as you can. Much thanks.
Upvotes: 0
Views: 498
Reputation: 4013
You just need to add the parameter to the shareMe()
function.
shareMe(shareOption: string){
this.sharingVar.share(shareOption)
.then(() => {
alert("Success");
})
.catch(() => {
alert("failed");
});
};
Update: added @Aluan Haddad suggestion because you are learning and this kind of things is something that you need to know now, not after you wrote 5k LoC.
Upvotes: 3