Is there a short and simple way to pass an RxJS Subject or BehaviorSubject to an an Angular 2 directive for two-way binding? The long way to do it would be as follows:
'If the mountain will not come to Muhammad, then Muhammad must go to the mountain'
Lets approach this from RxJS side instead of the NgModel side.
This solution limits us to only use BehaviorSubject's but I think this is a fair trade for having such an easy solution.
Slap this piece of code into your polyfills.ts. This enables you to bind the .value of a BehaviorSubject to an ngModel
import { BehaviorSubject } from 'rxjs';
Object.defineProperty(BehaviorSubject.prototype, 'value', {
set: function(v) {
return this.next(v);
}
});
And just use it like this.