2

I get data from AJAX query in Angular JS. It is information about user. There are two input radio button in page:

<input type="radio" ng-model="sex" value="1">
<input type="radio" ng-model="sex" value="2">

From AJAX I get field {'sex' : '1'}. How I can check input with value = 1 and set it value to ng-model?

2 Answers 2

5

Start by assigning a name to your inputs, to make them mutually exclusive:

<input type="radio" name="sex" ng-model="sex" value="1">
<input type="radio" name="sex" ng-model="sex" value="2">

Now, ng-model="sex" means that the inputs are populated based on the value of the sex property of the scope. So all you need to check the first input, from your controller, is

$scope.sex = '1';
Sign up to request clarification or add additional context in comments.

1 Comment

The same with input fields?
1

You can set that in your controller with your $scope.

<input type="radio" name="sex" ng-model="sex" value="1">
<input type="radio" name="sex" ng-model="sex" value="2">

$scope.sex = '1';

then you have set your variable for ng-model and you can use it.

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.