from @art-lowel: update onSelectChange to work with ngModel

Because we're working with ngModel, we're no longer getting a generic JS event in the onSelectChange, but simply the id of the selected option. I use that Id to find the option in the allOptions array that matches, and then use the data inside that matching option to navigate to the correct page.
This commit is contained in:
L. Henze
2019-10-08 12:40:57 -04:00
parent be19a2a961
commit c46480c97f

View File

@@ -69,17 +69,9 @@ export class ComcolPageBrowseByComponent implements OnInit {
map((urlSegments: UrlSegment[]) => urlSegments[urlSegments.length - 1].path)
);
}
onSelectChange(target) {
const optionIndex = target.selectedIndex;
const selectedOptionElement = target.options[optionIndex];
const paramsAttribute = selectedOptionElement.getAttribute('data-params');
console.log('change value ' + target.value + ' paramsAttribute ' + paramsAttribute);
if (paramsAttribute) {
/* console.log('Yes paramsAttribute ' + paramsAttribute);*/
this.router.navigate([target.value], { queryParams: { scope: paramsAttribute } });
} else {
/* console.log('No paramsAttribute ');*/
this.router.navigate([target.value]);
}
onSelectChange(newId: string) {
const selectedOption = this.allOptions
.find((option: ComColPageNavOption) => option.id === newId);
this.router.navigate([selectedOption.routerLink], { queryParams: selectedOption.params });
}
}