Hey guys so the issue that I'm having is that while I add an item to an array the ion-chip is being rendered and added correctly. And whenever I click the chip the value is being removed from the array, which is great! However, the chip remains on the screen.
Alright so the section I am doing is a search component, the search component has a an advanced search option. All options selected from there are sent to a search service that then adds or removes the values to an array, and the search component has a getter function that gets the array from service and adds it to its own array from which the search component's html file does a *ngFor. I have been reading this as well as this. While the latter is the closest I am not actually passing anything to a child. Now... you are probably saying to yourself "HEY!!! that sounds like you are reinventing the wheel and could use ngrx for a state management" in which case you are correct but I'm unable to use it. I have tried observables, IterableDiffers, but can't seem to get it to remove the ion-chip from the screen.
search html:
<ion-chip color="primary" *ngFor="let item of advancedSearchesSelected; let i = index">
<ion-icon name="close" color="danger" (click)="removeChipFromSearch(item); advancedSearchesSelected.slice(i, 1)"></ion-icon>
<ion-label> {{item}} </ion-label>
</ion-chip>
search.ts
advancedSearchesSelected: Array<string> = [];
constructor( public searchService: SearchService ){}
ngOnInit () {
this.advancedSearchesSelected = this.searchService.getSelectedValues();
}
removeChipFromSearch(chipToClear: string) {
this.searchService.updateSearchInfo('remove', chipToClear);
}
search service.ts
selectedValues: string[] = [];
public updateSearchInfo = (action: string, item: string) => {
console.log('UPDATE SEARCH INFO -->', action, item);
action === 'add' ?
this.selectedValues.push(item) :
this.clearSingleValue(item);
};
private clearSingleValue(item: string) {
this.selectedValues = this.selectedValues.filter(val => val !== item);
};
It is adding and removing fine, but the DOM element remains.