I have an ion-list items and user can add some data.
If I add data with my addNoteKeyboard() function, all will be ok, data will be shown properly and my list update.
Using addNoteMic() function, that is, use speech to text, nothing would be displayed until the first iteration with the screen (but i see the data immediately in console log).
.start() of course , allows to start recording and onresult = function(event) allows to receive the data.
That’s my code:
myList.html
<ion-item (click)="goToMore($event, singolo.alimento)">
{{singolo.alimento}}
</ion-item>
myList.ts
declare var SpeechRecognition: any;
@Component({templateUrl: 'build/pages/notes/notes.html'})
export class NotesPage {
recognition: any;
listaSpesa: any = [];
constructor(private nav: NavController) {
this.recognition = new SpeechRecognition();
this.recognition.onresult = (event => {
if (event.results.length > 0) {
console.log('--> risultati: ', event.results[0][0].transcript);
this.listaSpesa.push({alimento: event.results[0][0].transcript});
// console has the right result, but can not display when i push in my list
}
console.log('--> SpeechRecognition: listening END');
});
}
addNoteMic() {
console.log('--> SpeechRecognition: listening');
this.recognition.start();
}
addNoteKeyboard() {
let prompt = Alert.create({
title: 'Add Food',
inputs: [{
name: 'alimento'
}],
buttons: [{
text: 'Cancel',
cssClass: 'cancBnt'
},
{
text: 'Add',
handler: data => {
this.listaSpesa.push(data);
}
}],
});
this.nav.present(prompt);
}
}
I can see the output in console from event.results[0][0].transcript correctly, but nothing appears on the screen when i try to push it to my list.
I have to do something with the UI on my device to make the results magically appear, like a new registration or a new keyboard insert.
What’s the problem?
Thx in advantage.