Angular 5 个侦听器或按钮禁用指令 属性 更改

Angular 5 listener or directive for button disabled property change

我想为按钮创建一种指令(?)或侦听器。这个想法是当按钮被禁用时,它将移动并聚焦到下一个按钮。我想有一个循环来在不是所有元素之间移动,而是只在我将定义的按钮之间移动。

       <button id="btn1" #button1 [disabled]="checkIfIsDisable()" nextActivekBtn>
        Ändern
      </button>
      <button #button2 type="button"  [disabled]="checkIfIsDisable()">
        Text1
       </button>
      <button #button3 type="button"  [disabled]="checkIfIsDisable()">
        Text1
       </button>
      <button #button4 type="button"  [disabled]="checkIfIsDisable()">
        Text1
       </button>
      <button #button5 type="button"  [disabled]="checkIfIsDisable()">
        Text1
       </button>

我的想法是使用指令(如 nextActiveBtn),它将监听按钮 属性(禁用),然后调用父组件函数,该函数将决定要关注哪个按钮或元素。另外我想知道我是否可以在这些按钮上使用 ViewChildren?假设我在 html 中有很多按钮,但我想要它们的子集(只有这 5 个按钮)。我在函数中设置了 disabled 属性 但我真的很喜欢指令或独立于此函数的东西。

感谢任何建议或新想法。

指令不是一个很好的选择。更好的解决方案是在管理当前焦点按钮的组件中创建函数。我还向每个按钮添加 #navigableButton 并创建包含每个按钮的列表。

@ViewChildren('navigateButton') navigableButtons:QueryList <ElementRef>;

多亏了这些,我可以轻松地找到循环中的下一个活动按钮并移动到它。在禁用按钮的函数之后调用管理当前按钮焦点的函数。