title: md-autocomplete to search local(browser object) and if not found then look for database object
body: <p>I have created an md-autocomplete search and its searching the records using the $http from the database directly but what I want is that I want this md-autocomplete to search for the object from the array of objects which I am loading on the form load and if not found then it should go for the database search.</p>
  
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-js lang-js prettyprint-override"><code>(function() {
  
    'use strict'
    angular.module('GAiiNSApp').controller('ServicesMasterCtrl', ['$scope', '$http', 'LoadFormInteractivity', function($scope, $http, LoadFormInteractivity) {
  
      $scope.FormService.AllRecords = [{
          "id": 83,
          "servicename": "Blackberry Global Plan",
          "servicetype": "Postpaid",
          "monthlyrental": 299,
          "serviceremarks": "Testing",
          "servicestatus": 0,
          "activationdate": "/Date(1498852800000)/",
          "deactivationdate": null
        },
        {
          "id": 84,
          "servicename": "Internet",
          "servicetype": "Domain",
          "monthlyrental": 3090,
          "serviceremarks": "Use for Internet connection purpose only.",
          "servicestatus": 0,
          "activationdate": "/Date(1498852800000)/",
          "deactivationdate": null
        },
        {
          "id": 85,
          "servicename": "abc",
          "servicetype": "ddf",
          "monthlyrental": 4999,
          "serviceremarks": null,
          "servicestatus": 0,
          "activationdate": "/Date(1497211200000)/",
          "deactivationdate": "/Date(1497816000000)/"
        },
        {
          "id": 86,
          "servicename": "xxxxxxx",
          "servicetype": "fddf",
          "monthlyrental": 52,
          "serviceremarks": null,
          "servicestatus": 0,
          "activationdate": "/Date(1501617600000)/",
          "deactivationdate": "/Date(1499025600000)/"
        },
        {
          "id": 87,
          "servicename": "aed",
          "servicetype": "dfd",
          "monthlyrental": 120,
          "serviceremarks": null,
          "servicestatus": 0,
          "activationdate": "/Date(1498852800000)/",
          "deactivationdate": "/Date(1497902400000)/"
        },
        {
          "id": 89,
          "servicename": "sdfasdfsadfsadf",
          "servicetype": "fsdfasdfsdf",
          "monthlyrental": 10,
          "serviceremarks": null,
          "servicestatus": 0,
          "activationdate": "/Date(1499025600000)/",
          "deactivationdate": null
        },
        {
          "id": 94,
          "servicename": "e",
          "servicetype": "e",
          "monthlyrental": 10,
          "serviceremarks": null,
          "servicestatus": 0,
          "activationdate": "/Date(1499112000000)/",
          "deactivationdate": null
        }
      ];
  
      $scope.search = function(value) {
  
        //Here I want to use  $scope.FormService.AllRecords to search from in before it goes to the "NGAutoCompleteSearch"
  
        return LoadFormInteractivity.NGAutoCompleteSearch('/Assets/AssetsAPI/GetServiceRecord', value).then(function(res) {
          return res.data;
        });
      };
  
  
    }]);
  })();
  
  
  (function() {
    'use strict'
    angular.module('GAiiNSApp').factory('LoadFormInteractivity', ['$http', '$timeout', function($http, $timeout) {
  
  
  
      function NGSearch(url, val) {
        debugger
        return $timeout(function() {
          return $http({
            url: url,
            method: "GET",
            params: {
              searchvalue: val,
            }
          });
  
        }, 300);
  
      };
  
      return {
        NGAutoCompleteSearch: NGSearch
  
      };
  
    }]);
  
  })();</code></pre>
  <pre class="snippet-code-html lang-html prettyprint-override"><code>&lt;div ng-controller="ServicesMasterCtrl"&gt;
    &lt;md-autocomplete md-items="item in search(id)" md-search-text="id" md-min-length="2" md-delay="300" md-item-text="item.servicename" md-selected-item="selectedItem" md-no-cache="true" ng-model-options="{debounce: 500}" md-search-text-change="SearchChanged(id)"
      placeholder="Search service by id or name"&gt;
      &lt;md-item-template&gt;
        &lt;span class="item-title"&gt;
                                  Id:{{item.id}}
                              &lt;/span&gt;
        &lt;span class="item-metadata"&gt;
                                  &lt;span class="item-metastat"&gt;
                                      Service: &lt;strong&gt; {{item.servicename}} &lt;/strong&gt;
                                  &lt;/span&gt;
        &lt;span class="item-metastat" ng-if="!!item.montlyrental"&gt;
                                      MonthlyRental: &lt;strong&gt; {{item.montlyrental}} &lt;/strong&gt;
                                  &lt;/span&gt;
        &lt;span class="item-metastat" ng-if="!!item.activationdate"&gt;
                                      ActiveDate: &lt;strong&gt; {{item.activationdate |  ConvertToDate | date: 'dd-MMM-yyyy'}} &lt;/strong&gt;
                                  &lt;/span&gt;
        &lt;/span&gt;
      &lt;/md-item-template&gt;
      &lt;md-not-found&gt;
        No matching items found...
      &lt;/md-not-found&gt;
    &lt;/md-autocomplete&gt;
  &lt;/div&gt;</code></pre>
  </div>
  </div>
  </p>