I am currently working on customizing an example from ngx-chips to fit my specific needs. The challenge I am facing involves adjusting the onRemoving method example provided:
public onRemoving(tag: TagModel): Observable<TagModel> {
const confirm = window.confirm('Do you really want to remove this tag?');
return Observable
.of(tag)
.filter(() => confirm);
}
My goal is to replace windows.confirm
with a custom component that features an AskQuestion
method defined as follows:
AskQuestion(question: string, yesCallback: () => void, noCallback?: () => void): void {
The challenge lies in having multiple callbacks, whereas the ngx-chips components expect the method to return an observable. To resolve this, I attempted to convert the callbacks into observables using the bindCallback
method:
public onRemoving(tag: TagModel): Observable<TagModel> {
const choiceCallback = (choice: boolean): TagModel=> {
if (choice)
return tag;
};
this.questionService.AskQuestion("Remove item?", () => choiceCallback(true), () => choiceCallback(false))
return Observable.bindCallback(choiceCallback);
}
However, it seems like I might be making a mistake in my approach. Any suggestions or ideas?