I am making a post similar to a Facebook post, when I post data in the post when I type “@” to search data that return users names and if I type “#” first to call API and return available tags in ionic 4.
Here what I have done:
page.html
<ion-item>
<ion-textarea rows="3" (ionInput)="searchPeople($event)" cols="20" formControlName="comment"
placeholder="Tweet your reply" spellcheck="true" autoComplete="true" autocorrect="true" autofocus required>
</ion-textarea>
</ion-item>
page.ts
searchPeople(ev: any) {
// set val to the value of the searchbar
let val = ev.target.value;
let firstchar = val.charAt(0);
if (firstchar = "@") {
console.log("search people");
}
else if (firstchar = "#") {
console.log("hash tag");
} else {
console.log("error");
}
}
I did like this but it’s not working…
2
Answers
In HTML:
Change
(ionInput)="searchPeople($event)"
to(input)="searchPeople($event)"
..And in
TS: Change the function like,
Here the
firstchar
needs to check for value and it should not assign value.Working Example: https://stackblitz.com/edit/ionic-basic-form-1bjibt
working example