I'm still getting the hang of Rxjs. How do I go about initializing the first value of a BehaviorSubject
with data from a custom select box model? Here's what the model looks like:
private mainRangeDate: any = {beginDate: {year: 2018, month: 10, day: 9},
endDate: {year: 2018, month: 10, day: 19}};
constructor(public daterangeService: DaterangeService) { }
ngOnInit() {
console.log(this.mainRangeDate);
}
onDateRangeChanged(event: IMyDateRangeModel) {
this.daterangeService.dateRangeInterval.next(event);
console.log(event.beginDate);
}
This is what the service looks like:
@Injectable()
export class DaterangeService {
dateRangeInterval = new BehaviorSubject<Object>({});
constructor() { }
}
And here's how it's implemented in the component template:
<my-date-range-picker name="mydaterange" [options]="myDateRangePickerOptions"
[(ngModel)]="mainRangeDate" (dateRangeChanged)="onDateRangeChanged($event)" required></my-date-range-picker>
I want to set the BehaviorSubject
with the mainRangeDate
value without using ngOnInit
or relying on a timeout method. Any suggestions?