angulartreemat

How to get selected child node values in a angular mat tree


In angular 14 mat tree, have structure like parent --> child --> sub child . If I select child check box then it select all sub child elements. here I want only sub child selected values when I click on submit button.

here is the stack Blitz example I tried. https://stackblitz.com/edit/nested-multi-select-tree-demo-nymntq?file=app%2Ftree-nested-overview-example.html,app%2Ftree-nested-overview-example.ts

here when I click on submit, it's returning all selected dependents I want only sub child selected check values.

Please help me. Thanks in advance.


Solution

  • If hierarchy is upto 3 level & you want to get sub-child only, You Can easily get it with customizing your filter method in submit function.

    .filter((descendant) => descendant.isSelected && descendant['children'] === undefined)

    link