Issue
When a user clicks on a button on the same HTML page, I want to send the value of <ion-text>
to a TypeScript file. However, it did not work.
<ion-text [(ngModel)]='xy' ngDefaultControl >'variables from a global provider' </ion-text>
<ion-button (click)="callFun()">Save</ion-button>
TypeScript file:
xy:string;
ngOnInit() {
console.log(this.xy);
}
callFun(){
console.log(this.xy);
}
In the console, it returns undefined
. How can I obtain it? I’m unable to use the (ionChange)
function with ion-text
.
Solution
Sorry, I’m from Angular, but to work [ngModel] the ion-text component should to have a property "value",
I imagine you can use
<ion-text #myText>{{global.x}}</ion-text>`
<ion-button (click)="callFun(myText)">Save</ion-button>
callFun(text:any){
console.log(text.innerHTML);
}
But, apologies, I don’t know about Ionic 🙁
Answered By – Eliseo
This Answer collected from stackoverflow, is licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0