0

We're trying to get JqueryUI menus to work in our AngularJS app. From our Layout.js we're doing the following:

OURApp.controller('leftBarCtrl', ['$scope', function ($scope) {
    $scope.init = function () {
        $.ajax({
            url: "../Data/MainPageData",
            type: "GET",
            dataType: "Json",
            data: {},
            success: function (data) {
                if (data.Acknowledgment) {
                    $scope.$apply(function () {
                        $scope.subscriptionsModel = data.userSubscriptionsReponse.UserSubscriptionsObjects;
                        $scope.CompanyModel = data.userResponse.CompanyInformation;
                    })
                    $("#mdsubscriptionMenu").menu({
                        menus: "ul",
                        items: "li"
                    });

                }
               .......

But it doesn't seem to work. I read that moving the menu() call to an angular ".directive" restricted to 'A' should do the trick. Is that the only recommended way of getting JqueryUI components to work with AngularJS?

Thanks

1
  • 1
    don't mixup jquery with angular, use $http instead of $.ajax will remove your worry to run digest cycle Commented Jul 17, 2015 at 19:06

1 Answer 1

1

This sort of code needs to be in a directive. You shouldn't have jQuery in a controller.

Also you aren't accounting for any rendering time when you try to initialize the plugin outside of $apply(). When you are running the plugin code now $("#mdsubscriptionMenu") is likely still empty.

It would help to see the view html you are using to render the menu.

You can use the $last property of ng-repeat to trigger the menu plugin init

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

1 Comment

Yep, using the directive and the $last property did the trick! Thanks!

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.