1

I have a html template like this

<div class="row form-field" ng-show="specialRequestShown" id="specialRequests">
            <div>
                <label><input type="checkbox" class="needsclick"> Non-smoking Room</label>
            </div>
            <div>
                <label><input type="checkbox" class="needsclick"> Late Check-in</label>
            </div>
            <div>
                <label><input type="checkbox" class="needsclick"> Early Check-in</label>
            </div>
            <div>
                <label><input type="checkbox" class="needsclick"> Twin Bed</label>
            </div>
            <div>
                <label><input type="checkbox" class="needsclick"> Large Bed</label>
            </div>
            <div>
                <label><input type="checkbox" class="needsclick"> Extra Bed</label>
            </div>
            <div>
                <label><input type="checkbox" class="needsclick"> Airport Transfer</label>
            </div>
        </div>

        <button type="submit" class="btn btn-default gi-btn-next" ng-click="goToPayment()">
            Lanjutkan
        </button>
</div>

Question: In the function goToPayment(), how can I which checkboxes checked in div specialRequests without having to assign ng-model to each one of them? Function goToPayment() is located in the controller. Is there anyway to loop through the div specialRequests children?

1
  • if you do not want to assign any ng-model you can go for ng-checked Commented Mar 4, 2015 at 8:35

1 Answer 1

3

Try any of these:

$scope.goToPayment = function () {
    var checkedItems = document.querySelectorAll('#specialRequests input:checked')
}

OR

Inject $element into your controller:

$scope.goToPayment = function () {
    var checkedItems = $element[0].querySelectorAll('input:checked')
}
Sign up to request clarification or add additional context in comments.

3 Comments

$element is a jqlite wrapper of the dom element. $element[0] will give the native dom object, on which the method querySelectorAll is defined.
I got Error: [$injector:unpr] Unknown provider: documentProvider <- document when using document. I have added document as dependency in the controller. Do I need to add something elsewhere?
you dont need to inject document. Document is global object available everywhere in the browser

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.