Nate
Nate

Reputation: 7856

Get parent's scope array in directive

Sorry if it is a duplicate but I can't find the solution.

I have the following:

appDrct.directive('jsonArray', [function () {
    return {
        link: function (scope, element, attrs, ctrl) {
            console.log(scope.$parent.categories);
        }
    };
}]);

Which gives me an empty array (categories is not empty). If I print this: console.log(scope.$parent);, I can see my array with the items inside! Why is that? And how can I get my array?

Edit: It is in a modal view...

div(class="modal-header")
   div(json-array='categories')

Upvotes: 0

Views: 584

Answers (1)

Bogdan Savluk
Bogdan Savluk

Reputation: 6312

use just scope.categories...

scope.$parent.categories - would be right only if you have scope: true for your directive

Upvotes: 2

Related Questions