0

In my case, I want to render the bootstrap dropdown menu inside an ng-repeat and also it has to bind to data from API. My code is,

<ul class="nav nav-tabs list clearfix" id="myTab">
    <li class="item">
        <a href="#">Home & Garden</a>
    </li>
    <li ng-repeat="category in categories" class="item dropdown">
        <a href="#" class="dropdown-toggle"
            data-toggle="dropdown"
            id="dropdownMenu{{$index}}"
            aria-haspopup="true"
            aria-expanded="true">
                {{$index}}<span class="caret"></span>
        </a>
        <ul class="dropdown-menu" aria-labelledby="dropdownMenu{{$index}}">
            <li ng-repeat="a in category.subcategories">
                <a href="#">{{a.name}}</a>
            </li>
        </ul>
    </li>
</ul>

My controller code to get data from API call is,

$scope.getCategories = function () {
        userService.getCategories($rootScope.UrlProvider.categoriesList).then(function (response) {
            if (response.data.success === true) {
                $scope.categories = response.data.categories;
            }
            else {
                $rootScope.showFailureMsg($rootScope.resourcesData.GenericErrorMessage);
            }
        });
    }

This getCategories() will be called on ng-init.

In this when the parent array "$scope.categories" is static ($scope.categories=[1,2,3,4,5]), the dropdown toggle is working. But when its value is from API $http call success callback, the dropdown toggle is not working. Can you please help me to resolve this?

Thanks

3
  • 2
    Can you post an example of what your $http call looks like? Commented Nov 22, 2016 at 16:39
  • @machinehead115: Please refer my edit for the $http call. Commented Nov 23, 2016 at 7:24
  • I created a plnk with what you provided above, and made a mock $http request, and it seems to be working alright there. Compare between that and yours to see what's different. Also is your response coming back in the way that you expect it to? Commented Nov 23, 2016 at 17:23

0

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.