Emit a single value

I would like to emit a single value.

According to this post, the following should be valid:

var requestStream = Rx.Observable.just('https://api.github.com/users');

However, this does not work. just is not defined.

Has it been deprecated? Is there something that I can use instead?

A lot of the stuff is tucked away in: import 'rxjs/Rx'; You might try Observable.of for a single value.

This works for me (plunker):

import {Component} from 'angular2/core';
import {Observable} from 'rxjs/Observable';
import 'rxjs/Rx';

@Component({
  selector: 'my-app',
  providers: [],
  template: `
    <div>
      <h2>Hello {{test | async}}</h2>     
    </div>
  `,
  directives: []
})
export class App {
    test: Observable<any> = Observable.of("I'm an observable");
    constructor() {
  }
}

single, Returns an Observable that emits the single item emitted by the source Like first , but emit with error notification if there is more than one value. single marble � a Single passes this method the Throwable that caused the Single to be unable to emit an item A Single will call only one of these methods, and will only call it once. Upon calling either method, the Single terminates and the subscription to it ends.

.just(value) is from RxJS v4 while angular2 is using the v5. It has gone through an extensive rewrite, and it is still in beta so operators are missing/changed names in v5.

.of is just fine, as MarkM mentioned. I just wanted to add that you can also use .from which works if you have just one value, or an array of values. To reuse the example from your accepted answer, you would use something like (plunkr):

//our root app component
import {Component} from 'angular2/core';
import {Observable} from 'rxjs/Observable';
import 'rxjs/Rx';

@Component({
  selector: 'my-app',
  providers: [],
  template: `
    <div>
      <h2>Hello {{test | async}}</h2>

    </div>
  `,
  directives: []
})
export class App {
    test: Observable<any> = Observable.from(["I'm an observable"]);
    constructor() {
  }
}

single, Example 1: Emit first number passing predicate. ( StackBlitz | jsBin | jsFiddle ). // RxJS v6+. import { from } from 'rxjs';. import { single } from 'rxjs/operators';. . throttleTime didn't emit single values when leading was disabled and trailing enabled. e.g.: source: -a-----| time: ----| previous: -----| current: -----a-----| I've

Use the of function:

import {of} from 'rxjs';

var requestStream = of('https://api.github.com/users');

Single, A Single is something like an Observable, but instead of emitting a series of values — anywhere from none at all to an infinite number — it always either emits one value or an error notification. You could emit your event all the way back up the chain (although this can start to get quite messy if you're having to emit any further than grandchild to grandparent). You could use a dedicated state management system such as Vuex , which can help to simplify the process of emitting from deeply nested components.

Creating an observable from a single value, value : This can be any object; it is the value to be emitted on the sequence; scheduler : This is used to emit the value. The following code illustrates an example of� fix(throttleTime): leading and trailing true should only emit a single value per time frame #2749 Closed sod wants to merge 5 commits into ReactiveX : master from sod : throttle-time-single-emit

Add "single" as alternative for observables that only emit once or , Feature Request A special type for observable that only emits one value or throws error and then completes. Is your feature request related to a� the value of lovingVue will be passed to the checked prop. The lovingVue property will then be updated when <base-checkbox> emits a change event with a new value. Note that you still have to declare the checked prop in the component’s props option. Binding Native Events to Components

Observable, Observables are lazy Push collections of multiple values. calls the function is consuming it by "pulling" out a single return value from its call. The following example creates an Observable to emit the string 'hi' every second to a subscriber. A single variable equation is an equation in which there is only one variable used. (Note: the variable can be used multiple times and/or used on either side of the equation; all that matters is that the variable remains the same.) ${(x + 4)}/2 = 12$ $6x + 3 - 2x = 19$ $4y - 2 = y + 7$ These are all examples of single variable equations.

Comments
  • You can import just of with import 'rxjs/add/observable/of'; instead of import 'rxjs/Rx'
  • Now it is just a global function of("value")
  • for array of objects 'from' is throwing error: Cannot find a differ supporting object '[object Object]' and 'of' works fine