My main focus is on utilizing the Directive Controller exclusively. Please respond to the error mentioned, as I believe that for each instance of directive usage, Angular will go through the controller section specified in the Directive.
// declaration of module
var app = angular.module('myApp',[]);
// declaration of controller
app.controller('myCtrl',function($scope){
$scope.name = "Peter";
});
// declaration of app
app.directive('myStudent',function(){
return{
template: "Hi! Dear!! {{name}}<br/>",
controller:function(scope, elem, attr){
console.log("controller");
}
}
});
<body ng-app="myApp" ng-controller="myCtrl">
<my-student></my-student>
<my-student></my-student>
<my-student></my-student>
<my-student></my-student>
<my-student></my-student>
<script src="https://cdnjs.cloudflare.com/ajax/libs/angular.js/1.4.5/angular.min.js"></script>
</body>
Note:
Please provide insights on the error and usage of the directive controller only. I am aware that the same can be achieved using pre-link, post-link, or compile functions.
PS: I find it puzzling why some alien genius decided to downvote this!