10

I want to set default value of checkbox to checked ie., user must see that check box is checked when opening the page for some reason it does not work while using angularjs

here is my code

<html ng-app>

    <input type="radio" name="lookup"  ng-model="lookup" value="1" ng-checked="lookup==1" checked>Employee Lookup</input>
    <input type="radio" name="lookup"  ng-model="lookup" value="2" ng-checked="lookup==2">Company Lookup</input>
</html>
1
  • finally the fiddle is working i am keeping it here so that it may be useful to others link Commented Feb 19, 2013 at 13:33

1 Answer 1

14

Since you're using ngModel and value, the radio will automatically be selected if they match. Here is the HTML and JS:

<html ng-app ng-controller="testcontroller">
  <input type="radio" ng-model="lookup" value="1">Employee Lookup</input>
  <input type="radio" ng-model="lookup" value="2">Company Lookup</input>
</html>
function testcontroller($scope){
  $scope.lookup = 1;
}

And here is a working jsFiddle demonstration: http://jsfiddle.net/BinaryMuse/ZQDts/3/ (You might have been having trouble with your jsFiddle because you misspelled ng-app.)

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

Comments

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.