Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

JavaScript AngularJS Making Your Own Widget Your Own Widget: radio buttons

Martina Carrington
Martina Carrington
15,754 Points

In the videos, we used a dropdown to let the user choose their gender. This time, let's use radio buttons instead. Updat

i rewatch the video just in case if i miss anything but radio button i did correct for the male and female but for the gender it's saying i am missing input <!-- ADD THE "female" RADIO BUTTON HERE --> <input type="radio" name="gender" value="female" ng-model="user.gender" /> Female </label>

index.html
<!DOCTYPE html>
<html ng-app="treehouseCourse">
  <head>
    <title>Angular.js</title>
    <script src="js/angular.js"></script>
    <script src="app.js"></script>
  </head>
  <body ng-controller="userStepCtrl">
    <form name="demographics" class="fields">
      <label>
        <!-- ADD THE "male" RADIO BUTTON HERE -->
        <input ... /> Male
      </label>
      <label>
        <!-- ADD THE "female" RADIO BUTTON HERE -->
        <input ... /> Female
      </label>
    </form>
    <p>Selected gender: {{user.gender}}</p>
  </body>
</html>
app.js
angular.module('treehouseCourse', [])
  .controller('userStepCtrl', function ($scope, User) {
    $scope.user = User.get();
  })
  .factory('User', function () {
    var user = {
      gender: null,
      ageRange: null,
      surveyAnswers: {}
    }    
    return {
      get: function () {
        return user;
      }
    }
  })

1 Answer

andi mitre
STAFF
andi mitre
Treehouse Guest Teacher

Hi Martina,

You are very close..just add your code in the right area of the html doc.

<!DOCTYPE html>
<html ng-app="treehouseCourse">
  <head>
    <title>Angular.js</title>
    <script src="js/angular.js"></script>
    <script src="app.js"></script>
  </head>
  <body ng-controller="userStepCtrl">
    <form name="demographics" class="fields">
      <label>
        <!-- ADD THE "male" RADIO BUTTON HERE -->
        <input type="radio" name="gender"
           value="male" ng-model="user.gender" /> Male
      </label>
      <label>
        <!-- ADD THE "female" RADIO BUTTON HERE -->
        <input type="radio" name="gender"
           value="female" ng-model="user.gender" /> Female
      </label>
    </form>
    <p>Selected gender: {{user.gender}}</p>
  </body>
</html>