0

I have a form with a few checkboxes and form is being processed via angularjs. I have no knowledge about angular however I read about it to find a solution to my problem. I want a checkbox to be checked automatically when form is load. When I look at the codes below I don't understand anything so I need your help.

HTML: (I think this dynamically generates a few < li > options in the form GUI)

<ul class="sublist" style="padding-top:{{ $index * 38}}px;" ng-init="index=$index" ng-if="forActive == k" ng-repeat="(k, v) in forData">
    <li class="selected" ng-repeat="val in v">
        <a href="" title="">{{ val }} </a>
            <input value="{{ k }} > {{ val }}" type="checkbox" class="flc" ng-click="addForValue(k + ' > ' + val)" />
    </li>
</ul>

Content of array is this in angular: $scope.design.fors = [Adults > Men,Adults > Plus]

For example, When form is load, checkbox with value = Adults > Men shall be checked.

Thanks in advance

1 Answer 1

1

The way I usually handle this is by making my object a little more rich:

$scope.design.fors = [ 
    { value: "Adults > Men", checked: true},
    { value: "Adults > Plus", checked: false}]

Then in the view you can write something like:

<ul class="sublist">
    <li class="selected" ng-repeat="item in design.fors">
        <input type="checkbox" ng-model="item.checked" /> {{item.value}}
    </li>
</ul>
Sign up to request clarification or add additional context in comments.

1 Comment

I've changed the code to make it look like yours to solve the problem. Thanks

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.