I have a textarea with an option list. If one of the options is clicked and if enter key is pressed inside the text area the tag should be sent to the server and the text area should be cleared.
<ul>
<li *ngFor="let tag of tags">{{tag.tag}}</li>
<li><textarea #box (keyup)="searchTag(box.value)" (key.enter)="addTag(box.value)"></textarea>
<ul>
<li *ngFor="let tag of options" (click)="addTag(tag.tag)">{{tag.tag}}</li>
</ul>
</li>
How could I clear the text area, before or after information is sent to server? The clear command should call from the addTag function.
You can bind default value to textarea
<textarea [(ngModel)]="defaultValue"></textarea>
The component code:
export class TaggingComponent {
defaultValue: string = '';
addTag(value) {
this.defaultValue = '';
}
}
Be sure FormsModule
has been imported to app.module.ts
import { FormsModule } from '@angular/forms';
@NgModule({
imports: [
FormsModule
...
],
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With