Dependent

2019-08-21 12:48发布

问题:

I want to link multiple <material-dropdown-select>, using [(ngModel)] + (ngModelChange), making them dependent. (So not by using *ngFor + <material-select-item>.)

But I do not find how to make these <material-dropdown-select> dependent, such that when the "parent" is updated, the "first child" is updated/reset, and then when the first child is selected, the second is reset/updated, and so on.

I tried with querySelector() but obviously, this is not the good way.

Maybe with ViewChild/ViewChildren but the options list is not updated???

回答1:

Well I finally get what I needed.

I used @ViewChild to target the element in the page.

But changing the options "was tricky", as I had to first :

  • MaterialDropdownSelectComponent.options.dispose();

then

  • add the new list…

without the first step, the SelectionOptions<dynamic> is not updated…