angularjs getting value from scope object

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?

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!

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.