0

I want to create few directives for grid view.

Finally it should looks like:

<grid-table columns="table.columns">
    <grid-table-header></grid-table-header>
    <grid-table-filters></grid-table-filters>
    <grid-table-content rows="users"></grid-table-content>
</grid-table>

So - here is one main directive - table and another, optional directives for table header(columns names), filters(searching in table), table content.

And... in main directive(table) I have "columns" field - because I want to give informations about columns and want to use this data in child directives(header, filters, content).

Is it possible?

1 Answer 1

1

Yes you can get the data from parent directive to child directive through a controller.

angular.module('example')
   .directive('gridTable', function () {
      return {
         scope: {
           'columns': '='
        },
         controller: ['$scope', function($scope) {
            this.getColumns = function() {
               return scope.columns;
            }
         }]
      }
   });

And in Child directive:

angular.module('example')
   .directive('gridTableContent', function () {
      return {
         require: '^gridTable',
         ...
         link: function (scope, elem, attrs, gridTableCtrl) {
             console.log(gridTableCtrl.getColumns());
         }
      }
   });

The key thing here is the require property.

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

1 Comment

Thank u! It works for me :) One thing - scope in gridTable was not defined. I've changed it to $scope.

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.