-1

The controller retrieve data from a request and I have to update the html/input with the data retrieved. Sorry the question is this code doesn't work and I'm not figuring it out.

exports.SearchBarController = function($scope, $http) {
  
  $scope.update = function() {
    var query = encodeURIComponent($scope.searchText);

    $http.
      get('/api/v1/product/text/' + query).
      success(function(data) {
        $scope.results = data.products;
      });
  };

  setTimeout(function() {
    $scope.$emit('SearchBarController');
  }, 0);
};
<div class="search-bar-wrapper">
  <div ng-controller="SearchBarController">
      <input type="text" class="search-bar-input" ng-model="data.products" ng-        change="update()">
        <div class="product" ng-repeat="product in {{data.products}}">
        </div>
  </div>
Braiam
  • 1
  • 11
  • 47
  • 78
Walentes
  • 21
  • 4
  • 4
    What is your question? What errors are you seeing? What do you want in life? – Tyler Dec 14 '15 at 18:07
  • 1
    What are you trying to do? `data.products` is bound to a text field, i.e., only one value, and you're trying to iterate over it. Other than that, you'd also do `product in data.products`, not `{{data.products}}` – Tom Dec 14 '15 at 18:07
  • it should take the data from the http request while typing in the input field and then show the result with ngrepeat. – Walentes Dec 14 '15 at 18:12

1 Answers1

-1

exports.SearchBarController = function($scope, $http) {
  
  $scope.update = function() {
    var query = encodeURIComponent($scope.searchText);

    $http.
      get('/api/v1/product/text/' + query).
      success(function(data) {
        $scope.results = data.products;
      });
  };

  setTimeout(function() {
    $scope.$emit('SearchBarController');
  }, 0);
};
<div class="search-bar-wrapper">
  <div ng-controller="SearchBarController">
      <input type="text" class="search-bar-input" ng-model="searchText" ng-change="update()">
        <div class="product" ng-repeat="product in results">
        </div>
  </div>
dipesh
  • 158
  • 5