How to convert any[] to observable<any[]> in angular 6

how to convert observable<any> to array
convert observable to array angular 7
angular observable example
how to get value outside typescript subscribe function
return value from subscribe angular 6
angular observable map
angular convert json to observable
rxjs convert list to observable

I have a variable countryList : any[] which has following data:

  {"countrycode":"SH","countryname":"Saint Helena"},
  {"countrycode":"KN","countryname":"Saint Kitts and Nevis"},   
  {"countrycode":"LC","countryname":"Saint Lucia"},   
  {"countrycode":"IR","countryname":"Iran (Islamic Republic of)"},   
  {"countrycode":"IM","countryname":"Isle of Man"}, 
  {"countrycode":"SH","countryname":"Saint Helena"},
  {"countrycode":"KN","countryname":"Saint Kitts and Nevis"}, 
  {"countrycode":"LC","countryname":"Saint Lucia"},

I want to convert it into observable

How to do this ?

use of for return in observable in angular 6.

import { of } from 'rxjs';

    return of([
        { "countrycode": "SH", "countryname": "Saint Helena" }, 
        { "countrycode": "KN", "countryname": "Saint Kitts and Nevis" }, 
        { "countrycode": "LC", "countryname": "Saint Lucia" }, 
        { "countrycode": "IS", "countryname": "Iceland" }, 
        { "countrycode": "IN", "countryname": "India" }, 
        { "countrycode": "ID", "countryname": "Indonesia" }, 
        { "countrycode": "IR", "countryname": "Iran (Islamic Republic of)" }, 
        { "countrycode": "IQ", "countryname": "Iraq" }, 
        { "countrycode": "IE", "countryname": "Ireland" }, 
        { "countrycode": "IM", "countryname": "Isle of Man" }, 
        { "countrycode": "IL", "countryname": "Israel" }, 
        { "countrycode": "SH", "countryname": "Saint Helena" }, 
        { "countrycode": "KN", "countryname": "Saint Kitts and Nevis" }, 
        { "countrycode": "LC", "countryname": "Saint Lucia" }, 
        { "countrycode": "ZM", "countryname": "Zambia" }, 
        { "countrycode": "ZW", "countryname": "Zimbabwe" }

How to convert Observable<any> to array[], But GetCoutries will return Observable of any, unable to bind to rowData? How to convert Observable to CountryData[] in typescript ? you find  The above code is the promise representation of the snippet that we want to convert to using observables in such a way that we can integrate it with other, existing, observables. This article is about a function that's returning a Promise that we'll be converting into an Observable, not just a standalone Promise.

If you're using rxjs 6, you can simply use:

import { of } from 'rxjs';

// ...

let obs = of([
     {"countrycode":"SH","countryname":"Saint Helena"},
     {"countrycode":"KN","countryname":"Saint Kitts and Nevis"},
     // etc... 

If you're using an older version, replace of with Observable.of

Converting a Promise into an Observable, Tagged with rxjs, promises, observables, javascript. intended to give you an example on how we can convert any promise to an Observable. About. Description. This lesson describes how you can easily take any expensive method and wrap the call inside an RxJava Observable.. Once you start using RxJava, you will want all slow methods to return an Observable to enable you to use all of the benefits of RxJava.

Simply use the of operator from rxjs like this: return of(countryList)

Turn an array, promise, or iterable into an observable., signature: from(ish: ObservableInput, mapFn: function, thisArg: any, scheduler: Scheduler): This operator can be used to convert a promise to an observable! Converting Between Observables. We have various helper methods to convert an Observable type into another. For example: To convert any type to a Completable, either of the methods are available: toCompletable() ignoreElements() Similarly, to convert to Observable, toObservable() method is suffice. Flowable – toFlowable() Maybe – toMaybe()

To convert any[] to Observable(any[]) you can use of function if you are using rxjs package.

In component.ts

import { of } from 'rxjs';

// Other imports

let observableData = of([
Kitts and Nevis"},
Kitt and Nevis"}


refer this link

Using observables to pass values, An observable can deliver multiple values of any type—literals, messages, or events, This method is commonly used to convert an array to an observable. Any help will be greatly appreciated! There is no much resource out there regarding Behavior Subject. [UPDATE]: The reason I choose behavior subject instead of just observable to pass data between different part of my app: Behavior Subject VS regular Observable

Converting A Subject To An Observable Using RxJS In Angular 2, Ben Nadel demonstrates how to convert a Subject to an Observable in RxJS (​Ben's version) Casts any object that implements the observable  Angular2: convert array to Observable. Ask Question Asked 4 years, 2 months ago. Active 10 months ago. Viewed 62k times 55. 10. I have a component that gets the data

from, from<T>(input: any, scheduler?: SchedulerLike): Converts almost anything to an Observable. Convert an infinite iterable (from a generator) to an Observable​. I have a service which returns an Observable<Response> from a Http request, but I need to convert it do an Observable<PriceTag> to use it on a DataSource inside the connect method. Is there anyway to do this? This is the method from my service:

bindCallback, (args: any[]) => Observable<T> : A function which returns the Observable that delivers Convert jQuery's getJSON to an Observable API Observable<any[]>. I am new in angular2 and I broke spend a lot of time to find a solution, but I didn't. I want to convert a oberservable from a http call store in a class. I have the following: json file [{ "