1

I am facing a weird issue with ng-checked. I am applying it in my edit form to show selected option value but its not working. Following is my code and screen shot -

My controller code -

  if( true == $scope.employee.active ) {
    $scope.is_active_yes = true;
    $scope.is_active_no = false;
  }
  else {
    $scope.is_active_yes = false;
    $scope.is_active_no = true;
  }
});

Code in my Jade template -

.row
  .control-label.col-md-3 Is Active:
  .col-md-6
    input(type="radio", name="active", ng-model="employee.active", value="yes" ng-checked="{{is_active_yes}}")
    | Yes
    input(type="radio", name="active", ng-model="employee.active", value="no" ng-checked="{{is_active_no}}")
    | No

Though value is coming in my form for ng-checked but it is not applying to the markup. Let me know what I am doing wrong here ?

FYI - No error in the console and data is coming as you can check it in the screenshot.

ng-checked

3
  • 1
    It should be ng-checked="is_active_yes" Commented Aug 8, 2014 at 5:38
  • @CodeHater Oh wow ..yes it is the case..can you please tell me why it should not use {{ }} in this case, as I supposed to get values in jade template we need to add this Commented Aug 8, 2014 at 5:41
  • @CodeHater Please paste this as an answer..if possible with explanation as it solved my problem and I will accept it then Commented Aug 8, 2014 at 5:42

2 Answers 2

2

The ngChecked directive works on expressions and not on interpolated values. So don't wrap your expressions within {{ }}:

ng-checked="is_active_yes"
Sign up to request clarification or add additional context in comments.

3 Comments

Its working fine but whenever I save the edit form its losing the values though other values remain on the form...let me know what I am doing wrong ?
Create a fiddle or share the related html and controller code.
It was my bad..actually I am saving the boolean values in mongo but I am having yes/no (String) declared values for radio...just changed them to true/false and all working fine...resolved...thx for the help :) and have a g8 day :)
1

ng-checked is an Angular Attribute. Hence, it won't require {{ }} for interpolating the value of the scope variable you are passing. Hence you can directly use the variable name in the attribute as

ng-checked="is_active_yes"

1 Comment

Then why it not working if I adding ng-checked="employee.active" ? If I am using the above method for saving the edit form all values remain on the page, but I am loosing the scope for radio selection

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.