admin管理员组文章数量:1320661
I'm working with Angular material 1.0.5 and the md-checkbox directive. I was wondering if anyone knows how to make this into a tri-state checkbox.
The three states (and the associated variable values for my situation) are:
- Checked (true)
- Unchecked (false)
- Indeterminate (null)
For the version of Angular Material specified (1.0.5), when the checkbox is disabled, it shows the indeterminate state as a checkbox with a question mark in it.
However, when it is not disabled, it defaults back to a two state checkbox.
So far my failed attempts have been to wrapping the directive in another directive and trying to take over control of the md-checkbox.
Does anyone have any pointers in this situation?
Thanks.
I'm working with Angular material 1.0.5 and the md-checkbox directive. I was wondering if anyone knows how to make this into a tri-state checkbox.
The three states (and the associated variable values for my situation) are:
- Checked (true)
- Unchecked (false)
- Indeterminate (null)
For the version of Angular Material specified (1.0.5), when the checkbox is disabled, it shows the indeterminate state as a checkbox with a question mark in it.
However, when it is not disabled, it defaults back to a two state checkbox.
So far my failed attempts have been to wrapping the directive in another directive and trying to take over control of the md-checkbox.
Does anyone have any pointers in this situation?
Thanks.
Share Improve this question asked Mar 12, 2017 at 20:31 PrabuPrabu 4,1976 gold badges47 silver badges67 bronze badges1 Answer
Reset to default 10If you use angular material >1.0.8, you are able to use the md-indeterminate
attribute and manage the value with your own ng-change
function.
HTML
<md-checkbox ng-model="vm.checkModel"
md-indeterminate="vm.checkModel === null"
ng-change="vm.checkModelChange()">
Checkbox
</md-checkbox>
CONTROLLER
var checkValues = [false, true, null];
var index = 0;
vm.checkModel = checkValues[index];
vm.checkModelChange = function() {
vm.checkModel = checkValues[++index % checkValues.length];
}
Check this JSFIDDLE for angular material >1.0.8. (Best solution)
Check this JSFIDDLE for angular material 1.0.5. (I've used ng-class css to simulate the indeterminate state).
本文标签: javascriptTristate mdcheckbox with angular materialsStack Overflow
版权声明:本文标题:javascript - Tri-state md-checkbox with angular materials - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742065680a2418820.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论