0

I'm doing a pagination directive for my results and I can't seem to get over this problem. I have the following code (coffeescript):

window.pagination_services = angular.module("pagination_services", [])
    .directive('paginate', ->
        {
            restrict: 'E',
            replace: true,
            templateUrl: '../../assets/app/partials/services/pagination.html',
            scope: true,
            link: ($scope, $element, $attrs) ->
                console.log $scope.results
        }
    )

As you can see I have a console.log on $scope.results which returns:

e
    pagination: Object
        current_page: 1
        per_page: 20
        total_entries: 4097
        __proto__: Object
    sales: Array[20]
    __proto__: e

I need to be able to access the value of that pagination object. Something like:

$scope.results.pagination.current_page

but, no matter what I try, I get undefined.

Any ideas?

2 Answers 2

1

It looks like your directive depends on a controller which contains the "results" and you would want to inject that into this directive as a dependancy.

Say the controller is called as ResultsController

You might want to do something like

.directive('paginate', ->
        {
            restrict: 'E',
            replace: true,
            require : '^ResultsController'
            templateUrl: '../../assets/app/partials/services/pagination.html',
            scope: true,
            link: ($scope, $element, $attrs) ->
                console.log $scope.results
        }

Hope this helps!

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

2 Comments

Nope. the controller is a parent of this directive so I inherit it's attributes. I'll post the solution. It's all about async. My object was a httppromise that's why I couldn't fetch it. I can't answer my own question unfortunately
You can answer your own question.
0

You may have come to same conclusion ... but you should probably create a watch on your results (see scope doc) and check for new value before accessing.

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.