ng-controller inside a angularjs directive?

angularjs, angularjs-directive

Solution

You can put an ng-controller anywhere inside your ng-app including inside a directive template. for example this should work:

.directive("mainRightPanel", function(){
    return {
    template: '<div ng-controller="myCtrl">The rest of your directive can go here<div>'
  }
}

Problem

In many tutorials, I've seen controllers being passed into a directive like this: ``` .directive("mainRightPanel", function(){ return { templateUrl: "views/partials/panels/mainRightPanel.html", controller: function($http, $filter, $scope) { var info = this; $scope.authorWorks; $http.get('test/book_data.json').success(function(data){ $scope.authorWorks= data; }); }, } ``` However, I'd like to do it differently. Instead of writing javascript like the above, I'm having problems calling a controller from within the directive, like this ``` <div ng-app="mainLeftPanelModule" ng-controller="leftPanelController" class="list-group "> ``` Is this possible? And if it is, is there anything wrong with attaching a controller this way?

Original source