title: AngularJS : Cannot read property 'substring' of undefined
body: <p>Very new to AngularJS... I have an input field where I want the first letter to be capitalized. I added the below directive:</p>
  
  <pre><code>.directive('capitalizeFirst', function () {
      return {
          require: 'ngModel',
          link: function ($scope, $element, $attrs, $modelCtrl) {
  
              var capitalize = function (inputValue) {
  
                  var capitalized = angular.uppercase(inputValue.substring(0, 1)) + inputValue.substring(1);
                  if (capitalized !== inputValue) {
                      $modelCtrl.$setViewValue(capitalized);
                      $modelCtrl.$render();
                  }
                  return capitalized;
              };
              $modelCtrl.$parsers.push(capitalize);
              capitalize($scope[$attrs.ngModel]); // capitalize initial value
          }
      };
  })
  </code></pre>
  
  <p>It works! But it fires an error in my console:</p>
  
  <p><strong>TypeError: Cannot read property 'substring' of undefined</strong></p>
  
  <p>Can anybody let me know what is wrong? Thanks in advance!</p>