Angular - 检查是否选择了所有选项以启用按钮 [英] Angular - Check if all options are selected to enable button
问题描述
这是一个测验应用程序,在这种情况下,我的下一个按钮将重定向到另一个页面,并且默认情况下它处于禁用状态.如果我选择它应该启用的所有选项.
This is a quiz app, in this scenario my next button will redirect to another page and it's disabled by default. If I choose all the options it should enable.
注意:
我选择选项和选择正确/错误的功能运行良好,我只是无法弄清楚在选择每个选项时如何启用.
My functionality of selecting options and choosing correct/wrong is working fine, I just can't figure out how to enable when each single option is selected.
有什么帮助或建议吗?工作演示:https://stackblitz.com/edit/angular-ivy-5qtyxy
Any help or suggestions? Working demo: https://stackblitz.com/edit/angular-ivy-5qtyxy
buttonDisabled = true;
<button class="btn-next" [disabled]="buttonDisabled">
Next
</button>
推荐答案
我对此的看法是将 buttonDisabled
定义为 getter,然后评估每个问题的状态是否允许导航下一页...
My take on this is to define the buttonDisabled
as a getter and then evaluate for each question if it's status allows for the navigation to the next page...
在我的实现中,用户必须选择类型 2 问题的所有答案,但只选择类型 1 问题的一个答案.如果这不是您想要的,请在评论中说明,这对我来说似乎合乎逻辑.我希望它已经对你有所帮助.
In my implementation the user has to select all of the answers of the type-2-questions, but only one answer on the type-1-questions. If this is not what you want please state so in the comments, it's just what appeared logical to me. I hope it helps you already.
有什么问题吗?问问吧.
Any questions? Just ask.
这篇关于Angular - 检查是否选择了所有选项以启用按钮的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!