0

this is my html code

<input type="text" ng-model="ngModelOptionsSelected" 
 placeholder="Enter Story Title"
 ng-model-options="modelOptions" 
 ng-change="onChangeFunction()"
 typeahead-on-select="typeaheadOnSelectFunction()"
 uib-typeahead="document as document.Name for document in getStory($viewValue)" 
 class="form-control">

this is my .js code

$scope.getStory = function (val) {
storyService.GetStoryByName(cacheService.project.projectId,val).success(function (data) {
                if (data.ResponseStatus) {
               debugger;
                    return  data.ResponseData;
                } else {
                    //On failure
                    toastr.error(data.ErrorData.Error);
                }
            });
        };

function output which returns data like ResponseData =

[{"Id":211380.0,"Name":"dixit"},{"Id":211488.0,"Name":"dixit ade"},{"Id":251541.0,"Name":"dixit"},{"Id":842671.0,"Name":"dixit"},{"Id":842672.0,"Name":"dixit choksi"}]

but i am not able to bind data in typeahead.

please help me i am stuck. thanks

2
  • Could you share the console errors? Commented Oct 14, 2016 at 15:00
  • @Ritwik Sen no error on consol. Commented Oct 15, 2016 at 4:54

1 Answer 1

1

Your function $scope.getStory() doesn't actually return anything, your return line return data.ResponseData; is nested within another function.

The uib-typeahead directive is able to work with promises so you just need to return the promise from your function.

$scope.getStory = function (val)
{
    return storyService.GetStoryByName(cacheService.project.projectId, val).success(function (data)
    {
        if (data.ResponseStatus)
            return data.ResponseData;

        toastr.error(data.ErrorData.Error);

        return [];
    });
};

You can also add another property to the directive, typeahead-loading="isLoading", that will toggle whilst the promise resolves. It can be used to show/hide loading spinners for example!

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.