I've been attempting to create a reusable auto search feature in an AngularJS factory. Below is my code snippet, but I keep encountering the error: "Cannot read property 'then' of undefined". I've searched on Google and Stack Overflow for a solution but haven't been able to resolve it.
(function() { 'use strict' angular.module('App').factory('LoadFormActivity', ['$http', '$q', function($http, $q) { function NGAutoCompleteSearch(url, val) { var def = $q.defer(); $http.get(url, { params: { searchvalue: val } }).then(function(response) { debugger; def.resolve(response); }, function(response) { debugger; def.reject(response); }); return def.promise; }; return { NGAutoCompleteSearch: NGAutoCompleteSearch }; }]); })(); //Controller. (function() { 'use strict' angular.module('App').controller('ServicesMasterCtrl', ['$timeout', '$scope', '$filter', '$http', 'NGAutoComplete', 'LoadFormActivity', function($timeout, $scope, $filter, $http, NGAutoComplete, LoadFormActivity) { $scope.FormService.AutoSearch = {}; $scope.FormService.AutoSearch.Search = function(id) { LoadFormActivity.NGAutoCompleteSearch('/Assets/AssetsAPI/GetServiceRecord', id).then( function(data) { console.log(JSON.stringify(data)); }); }; }]); })();
Could someone lend a hand with this issue?