Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

227
Visualizações
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?

over 4 years ago · Santiago Trujillo
3 Respostas
Responde à pergunta

0

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() {
  }
}
over 4 years ago · Santiago Trujillo Relatório

0

.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() {
  }
}
over 4 years ago · Santiago Trujillo Relatório

0

Use the of function:

import {of} from 'rxjs';

var requestStream = of('https://api.github.com/users');
over 4 years ago · Santiago Trujillo Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda