Reputation: 1670
I have a custom directive, and also I have a controller in a separate file. I know I can add a controller to this directive in this way
.directive("languageFooter", function () {
return {
restrict: "E",
templateUrl: "templates/footer.html",
controller: ['$scope', function($scope) {..}
};
});
But I was wondering if it's possible to add a controller that I have in a separate file something like this
.directive("languageFooter", function () {
return {
restrict: "E",
templateUrl: "templates/footer.html",
controller: "customController"
};
});
Upvotes: 1
Views: 4426
Reputation: 4329
You can ofcourse add controller this way. only thing is that you should load the controller js file before directive js file. Also as per Kulbhushan comment, the second approach is more in practice
Upvotes: 1