Encountering an issue when trying to incorporate a directive into my website:
Error: [ng:areq] Argument 'MainController' is not a function, got undefined
This problem arises specifically when I include the welcome-directive (welcome.js) in my site. Removing the import allows the controller to function without errors.
Here is the content of my index.html:
<body ng-app="my-app">
<div ng-controller="MainController">
<welcome></welcome>
</div>
<!-- Angular -->
<script src="bower_components/angular/angular.js"></script>
<script src="js/app.js"></script>
<script src="js/controllers/mainController.js"></script>
<!-- This line can be removed for the controller to work normally -->
<script src="js/directives/welcome.js"></script>
</body>
app.js
(function() {
var app = angular.module('my-app', []);
})();
mainController.js
angular.module('my-app', [])
.controller('MainController', ['$scope', function($scope) {
console.log('Controller working');
}]);
welcome.js
angular.module('my-app', [])
.directive("welcome", function() {
return {
restrict: "E",
template: "<div>Test test.</div>"
};
});