0

I have following service method with return statement.

this.partnersListForAutocomplete =  function (container, options) {
         $("#autocompletePartners").kendoAutoComplete({
             dataSource :  {
                 type: "json",
                 serverFiltering: true,
                 transport: {
                     read: function (options) {
                         console.log("List");
                         console.log(options.data);
                         requestParams = {
                             "entityName": "dvd",
                             "page": 1,
                             "pageSize": 20,
                             "filter": options.data.filter,
                             "sort": [
                                 {
                                     "field": "name",
                                     "ord": "asc"
                                 }
                             ]
                         };
                         ApiService.doHttpRequest(
                             "POST",
                             $rootScope.apiBaseUrl + "partner/search",
                             requestParams
                         )
                             .success(function (data, status, headers, config) {

                             })
                             .error(function (data, status, headers, config) {

                             });
                     }
                 }
             },
             dataTextField: "name"  ,
             dataValueField: "id",
             filter: "contains",
             minLength: 1,
             change  : function (e) {
                 // I WANT RETURN IT
                 return "test";

             },
             select  : function (e) {
                 // I WANT RETURN IT
                 return "test";
             }
         });
     };

Which is called by this code from controller method:

  selectedPartnerId = GlobalHelperService.partnersListForAutocomplete();

  $scope.projectDetail.test = selectedPartnerId;

Problem is that returned value is not passed into selected scope.

How can i solve it please?

Note: Method for autocomplete is assync.

Thanks for any help.

1 Answer 1

1

You have a couple of options that I can think of from the top of my head:

You could return a promise from the partnersListForAutocomplete() method, and then inside your controller you would then do something like the following pseudocode:

GlobalHelperService.partnersListForAutocomplete()
    .then(function(response) {
        $scope.projectDetail.test = response;
    });

Or, accept a callback to your partnersListForAutocomplete() method, and then inside your controller you would then do something like the following pseudocode:

GlobalHelperService.partnersListForAutocomplete(function(response) {
    $scope.projectDetail.test = response;
});
Sign up to request clarification or add additional context in comments.

2 Comments

Thanks, but i always get Cannot read property 'then' of undefined
Are you returning a promise from the partnersListForAutocomplete() method?

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.