0

I have dropdown Boxes in my forms which use via a custom component and i populate them with data by pasing the lookup value via a GUID to the component. All works as expected and i get my data etc. But now i need to be able to also clear the data in dropdown based on user selection. Lets say user selects in first dropdown fruits, based on that i want to provide in the selection all fruits which i have no problem doing. But now user goes back and changes its selection from fruits to soda, which means the previous selected apple is no longer valid and needs to be cleared. So i am looking for a simple way to clear all values from a dropdown box.

to get my data into dropdown i call

socialOptions$: Observable<Array<IServerDropdownOption>>;
ngOnInit() { 
    this.socialOptions$ = this.guidService.fetchAll(this.guids.SOCIAL_LABELS).pipe(shareReplay());
  }

when i try this.countryOptions$ = [] i get this error enter image description here

1
  • This is how declaration should made be. this.countryOptions$ = Observable<any[]> If its is being used in template pipe it ascountryOptions$|async Commented Oct 10, 2019 at 0:30

1 Answer 1

7

If all you want is to get an empty array from your Observable, then the following should do

import { of } from 'rxjs';
...
this.countryOptions$ = of([]);

Explanation

In your question you are trying to do the following this.countryOptions$ = [] which is incorrect because you are trying to assign an array to type Observable which are not compatible. The Rxjs of operator creates an Observable from any provided array. Read more about the of operator here.. https://www.learnrxjs.io/learn-rxjs/operators/creation/of

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.