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

help

Create a function that receives a value and transforms it from seconds to milliseconds by multiplying it by 1000 and returning it. Then attach this new function to the appropriate array on ngModelCtrl, so that duration is multiplied by 1000 before it's populated in the milliseconds input field.

code: idk what im doing

angular.module('myApp', []) .controller("myController", function($scope) { $scope.duration = 27; }) .directive('myDirective', function () { return { require: 'ngModel', priority: 1, link: function ($scope, $element, $attrs, ngModelCtrl) {

    var parser = function (value) {
      return value / 1000;
    };
    ngModelCtrl.$parsers.push(parser);



  }
}
}) ;

http://teamtreehouse.com/library/angularjs-2/extending-inputs/extending-inputs-formatters

2 Answers

Jeremy Faith
PLUS
Jeremy Faith
Courses Plus Student 56,696 Points

I created a function named test (not very specific for task but it worked) that just multiplied a value by 1000. I then attached it to ngModelCtrl using $formatters.push().

 var test = function (value) {
          return value*1000;
        }

        ngModelCtrl.$formatters.push(test);

This worked for me hope it works for you.

var parser = function (value) { return value*1000; }; ngModelCtrl.$parsers.push(parser);