title: Javascript error trying to perform a search filter using Angular JS
body: <p>In my app Im trying perform a search filter on names by partial match from the beginning. Heres an example of what Im trying to do: </p>
  
  <p>Lets say I have a list of names:</p>
  
  <pre><code>Ben
  James
  Adam
  Judy
  Andy
  </code></pre>
  
  <p>and enter the text <code>"a"</code> in my search field, it would return </p>
  
  <pre><code>Adam
  Andy
  </code></pre>
  
  <p>if I further enter <code>"an"</code> in my search field, it would return</p>
  
  <pre><code>Andy
  </code></pre>
  
  <p>In my app.js, I have the code:</p>
  
  <pre><code>var myApp = angular.module("myApp", []);
  
  myApp.controller("myController", function ($scope) {
      var employees = [
          { name: "Ben", gender: "Male", salary: 55000, city: "London" },
          { name: "Jane", gender: "Female", salary: 62000, city: "Albany" },
          { name: "Rick", gender: "Male", salary: 65000, city: "Los Angeles" },
          { name: "Pam", gender: "Female", salary: 60000, city: "Paris" },
          { name: "Josh", gender: "Male", salary: 68000, city: "Brussels" },
      ];
  
      $scope.employees = employees;
  
      $scope.filtered = function (item) {
          if ($scope.searchName == undefined) {
              return true;
          } else {
              if (item.name.toLowerCase().startsWith($scope.searchName.toLowerCase()) != -1) {
                  return true;
              }
          }
  
          return false;
      }
  });
  </code></pre>
  
  <p>And in my html page, I have the following line which displays the list of employees:</p>
  
  <pre><code>&lt;tr ng-repeat="employee in employees | filter: filtered"&gt;
  </code></pre>
  
  <p>And the following line which the user inputs the search text: </p>
  
  <pre><code>&lt;input type="text" placeholder="Search Name" ng-model="searchName.name"&gt; &lt;br&gt;&lt;br&gt;
  </code></pre>
  
  <p>However, when I attempt to test this, I get the error:</p>
  
  <pre><code>Error: $scope.searchName.toLowerCase is not a function. (In '$scope.searchName.toLowerCase()', '$scope.searchName.toLowerCase' is undefined)
  </code></pre>