0

I have problem on md-checkbox.
I need to use single selection of check but I couldn't make it.
I referred md-radio-button for groupings but I don't want to use radio button.

Below is my code:

<ul>
    <li>
        <md-checkbox ng-model="data1"  aria-label="Checkbox 1">
            Full Time
        </md-checkbox>
    </li>
    <li>
        <md-checkbox ng-model="data2" aria-label="Checkbox 1">
            6AM - 12 PM
        </md-checkbox>
    </li>
    <li>
        <md-checkbox ng-model="data3" aria-label="Checkbox 1">
            12PM - 9PM
        </md-checkbox>
    </li>
</ul>

Can anyone help me.

1 Answer 1

1

I think what you want is md-radio-group functionality but with checkboxes.

To achieve this you can use ng-true-value, ng-false-value and a change handler (to make sure atleast one checkbox is checked):

<md-checkbox ng-model="data" ng-true-value="'data1'" ng-false-value="false" ng-change="!data && (data='data1')">

Here's a fiddle : https://jsfiddle.net/d2fev8ey/33/

Sign up to request clarification or add additional context in comments.

12 Comments

Excellent Thank you
@Santhosh Welcome! :) Can you also upvote or atleast accept my answer?
@Santhosh I think you are new on StackOverflow... Here you are supposed to accept the answer which worked for you... So I am not asking for a favour.... I am asking for what I deserve...
Hi Devansh i can't upvote because as i am new to stackoverflow. Thanks i will update when i got reputation in this account.
@Santhosh but you can still accept the answer if not upvote because you are the asker... Give it a try... If it doesn't work let me know...
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.