How to two-way bind my own RxJS Subject to an [(ngModel)]?

前端 未结 6 623
一生所求
一生所求 2021-01-31 15:42

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:



        
6条回答
  •  粉色の甜心
    2021-01-31 16:25

    The closest I can think of is to use a FormControl:

    import { FormControl } from '@angular/forms';
    
    @Component({
        template: ''
    })
    class MyComponent {
        control = new FormControl('');
        constructor(){
            this.control.valueChanges.subscribe(()=> console.log('tada'))
        }
    }
    

提交回复
热议问题