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 was rewatching the video see if i miss anything but i think got confused . i understand the radio button

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;
      }
    }
  })