The application scenario of Rxjs assignment in angular.

now has the following scenario, where there are two attributes in Component, and the code is as follows:

// OnInit
yearList: Observable<string[]>; 

// 0yearListyearList0year
year: BehaviorSubject<string> = new BehaviorSubject("0"); 

ngOnInit() {
    this.yearList = this.service.getYearList()
        .withLatestFrom(this.year)
        .map(([yearList, year]) => {
            if (year === "0" && yearList.length > 0) {
                this.year.next(yearList[0]);
            }
            return yearList;
        });
}

the above code means:
gets the yearList data in the component OnInit event, and its result is an array of strings, and then gets the zero from this array and assigns it to year. In the process of assignment, I use the operator map method, and finally I give yearList to return in this method.

although there is no problem in running, I always feel that this is not a good method. As far as I understand it, the map method should be an operation used to convert yearList into other data, similar to the Array.map method.

what I want to ask is, is there any other good way to assign values like this?

Mar.03,2021

    this.yearList = this.service.getYearList()
        .do(yearList => {
            if (this.year.value === '0' && yearList.length > 0) {
                this.year.next(yearList[0]);
            }
        })
Menu