El operador publish () devuelve ConnectableObservable y necesita usar el método connect () para suscribirse a los observables.
Sintaxis
publish()
Ejemplo
import { interval,Observable } from 'rxjs';
import { filter, publish } from 'rxjs/operators';
var observable = new Observable(function subscribe(subscriber) {
try {
subscriber.next(Math.random());
} catch (e) {
subscriber.error(e);
}
});
const observable1 = publish()(observable);
const subscribe_one = observable1.subscribe(
x => console.log("Value from Sub1 = "+x)
);
const subscribe_two = observable1.subscribe(
x => console.log("Value from Sub2 = "+x)
);
observable1.connect();
Salida