0

Am new to angularJS, and am not able to make out why the directive is not getting called I have separate js file controller for app, separate js file directive for app; Trying to create separate files for each;

Plunker Link of the code

HTML Code

<vertical-table data='fieldsList'></vertical-table>

Controller Code

app.controller('MainCtrl', function($scope) { $scope.fieldsList =[{},{},{}]; });

Directive Code

angular.module('plunker').directive('verticaltable', function () {
  console.log("field list initialzed");
    return{
        restrict: 'AE',
        template: 'table.html',
        replace: true,
        transclude: true,
        scope : {
            data: "="
        },
        controller: function($scope, $elem){
          console.log("controller");

        },
        link:function($scope, elem){
          console.log("link");
        }
    };
});
4
  • I'm experiencing same issue, can't wait for the answer... Commented Jan 26, 2014 at 8:20
  • try .directive('verticalTable' instead of .directive('verticaltable', (notice the capital T in Table) Commented Jan 26, 2014 at 8:29
  • Facing new issues :-) Error: Template must have exactly one root element. was: table.html Commented Jan 26, 2014 at 8:31
  • Use templateUrl instead of template Commented Jan 26, 2014 at 8:38

1 Answer 1

1

There are some mistakes to fix:

angular.module('plunker').directive('verticalTable', function () {
      console.log("field list initialzed");
        return{
            restrict: 'AE',
            templateUrl: 'table.html',
            replace: true,
            transclude: true,
            scope : {
                data: "="
            },
            controller: function($scope){
              console.log("controller");

            },
            link:function(scope, elem){
              console.log("link");
            }
        };
    });
  • Use templateUrl instead of template
  • Replace .directive('verticaltable' with .directive('verticalTable', (notice the capital T in Table)
  • Remove the $elem parameter in your directive's controller because you don't have a service named $elem.

DEMO

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

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.