Could someone please help me understand why I am getting an "Argument 'MainCtrl' is not a function, got undefined" error? It seems to be related to module dependency injection when using directives.
angular.module('app', [])
.controller('MainCtrl', [function() {
var self = this;
self.name = "will this work";
self.items = [
{
name: "name 1",
test: "test 1"
},
{
name: "name 2",
test: "test 2"
}
];
}]);
angular.module('app',[])
.directive('typeahead', [function() {
return {
templateUrl: 'type-ahead.html',
restrict: 'AEC',
scope: {
items: '=',
prompt: '@',
title: '@',
subtitle: '@',
model: '=',
onSelect: '&'
}, <...more code>
However, everything works fine if I remove the
[ ]
module dependency brackets from the directive declaration like this:
angular.module('app').directive('typeahead', ...)
Alternatively, it also works if I define the directive after the controller like this:
angular.module('app', [])
.controller('MainCtrl', [function() {
var self = this;
self.name = "will this work";
self.items = [
{
name: "name 1",
test: "test 1"
},
{
name: "name 2",
test: "test 2"
}
];
}])
.directive('typeahead', [function() {
return {
Thank you in advance for any assistance!