fitness-set.js

angular.module('homepage').
directive('addNewSet', function ($timeout) {
  function Set() {
    return {
      repetition: '',
      weight: '',
      time: '',
      distance: ''
    }
  }

  return {
    link: function (scope, element, attribute) {
      element.on('keyup', function(event){
        if(scope.index + 1 == scope.sets.length) {
          var code = event.keyCode || event.which;
            // Skip adding row if key pressed is 'Tab', 'Shift' or 'Esc'
            if(!(code == 9 || code == 16 || code == 27)) {
              console.log('keyup happening');
              $timeout(function () {
                scope.sets.push(new Set());
                scope.$apply();
              });
            }
          }
        })
    },
    restrict: 'E',
    replace: true,
    scope: {
      index: '=',
      sets: '=data'
    },
    templateUrl: 'components/feature-components/fitness/fitness-set.html'
  }
});