I would like to call the method onRemoveLastTag()
with dual conditions.
I want to call the method only when the form is empty and keyup.backspace
.
Backspace should operate normally while there is still text in the input field. This is an Angular 11 application.
<form [formGroup]="searchForm">
<label for="search"></label>
<span class="chippie"
*ngFor="let tag of selectedTags; let i=index">
{{tag}}
<a class="close"
(click)="onRemoveTag(i)"
> X</a></span>
<input
id="search"
formControlName="search"
type="text"
placeholder="Your tag goes here"
class="form-control"
autocomplete="off"
(keyup.enter)="addTag($event)"
(keyup.backspace)="onRemoveLastTag()"
(keyup)="openDropdown()"
(keyup.arrowLeft)="toggleDropdown()"
>
</form>
onRemoveLastTag() {
this.selectedTags.pop();
console.log(this.selectedTags)
}
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…