jquery - AngularJs autocomplete TypeError: this.source is not a function -
i have following html textbox autocomplete feature.
<body ng-controller="homecontroller" ng-init="init()"> <div class="col-xs-4 search-bar-position" > <form role="search" > <div class="input-group" > <input auto-complete type="text" id ="search" value="abcd" class="form-control text-center" placeholder="search products" name="srch-term" id="srch-term" style="width:400px;height:30px;" ng-change="autocomplete()" ng-model="searchchar" /> <div class="input-group-btn"> <button class="btn btn-default" style="height:30px;" type="submit"><i class="glyphicon glyphicon-search"></i></button> </div> </div> </form> </div> </body> angularjs controller follows.
angular.module('gbuyref').controller('homecontroller',function ($scope,$window,$http,$cookies) { $scope.autocomplete = function() { searchchar = $scope.searchchar $http({ method : 'post', url : '/autocomplete', data : {"searchchar" : searchchar}, headers : { 'content-type': 'application/x-www-form-urlencoded' } // set headers angular passing info form data (not request payload) }).success(function(data, status, headers, config) { $scope.products = json.parse(json.stringify(data)); $scope.product_list = $scope.products.products; console.log($scope.product_list); }).error(function(data, status, headers, config) { $scope.status = status; $window.alert("error") }); } }); angularjs directive follows:
angular.module('gbuyref').directive('autocomplete', function() { return { restrict: 'a', link: function(scope, elem, attr, ctrl) { // elem jquery lite object if jquery not present, // jquery , jquery ui, full jquery object. elem.autocomplete({ source: scope.product_list }); } }; }); when try use autocomplete feature entering textbox, below error in firebug
typeerror: this.source not function this.source( { term: value }, this._response() );
$scope.product_list getting response form backend ["samsung chromebook", "sony playstation 4", "sony vaio", "sony vaio 17"] when press s in textbox
i did @ other post not figure out actual solution. appreciated.
Comments
Post a Comment