Just return the BehaviorSubject from your channel, which can then be connected to the angular asynchronous channel.
A small example (put it in your channel conversion method) that should give you a βvalueβ after 3 seconds:
const sub = new BehaviorSubject(null); setTimeout(() => { sub.next('value'); }, 3000); return sub;
Full example:
import { IOption } from 'somewhere'; import { FormsReflector } from './../forms.reflector'; import { BehaviorSubject } from 'rxjs'; import { Pipe, PipeTransform } from '@angular/core'; @Pipe({ name: 'getOptions' }) export class GetOptionsPipe implements PipeTransform { public transform(value, ...args: any[]) { const _subject = new BehaviorSubject('-'); if (args.length !== 2) { throw `getOptions pipe needs 2 arguments, use it like this: {{ 2 | getOptions:contract:'contractType' | async }}`; } const model = args[0]; if (typeof model !== 'object') { throw `First argument on getOptions pipe needs to be the model, use it like this: {{ 2 | getOptions:contract:'contractType' | async }}`; } const propertyName = args[1]; if (typeof propertyName !== 'string') { throw `Second argument on getOptions pipe needs to be the property to look for, ` + `use it like this: {{ 2 | getOptions:contract:'contractType' | async }}`; } const reflector = new FormsReflector(model); reflector.resolveOption(propertyName, value) .then((options: IOption) => { _subject.next(options.label); }) .catch((err) => { throw 'getOptions pipe fail: ' + err; }); return _subject; } }
source share