I am new to AngularJS and using plnkr.co to learn how to use angular. I have having some difficulty registering a Controller this is stored in a separate .js from where the module is initialized. Can anybody tell me why the below does not work?
index.html file
app.js File
angular.module('plunker', []);
mainCtrl.js File
angular.module('plunker')
.controller('MainCtrl', ['$scope', function($scope) {
$scope.name = 'GitHub';
}]);
For me, this produces an Argument 'MainCtrl' is not a function, got undefined.
Replace
<script scr="mainCtrl.js"></script>
with
<script src="mainCtrl.js"></script>
Because of the typo (scr
instead of src
), the source file holding MainCtrl
is not loaded, therefore MainCtrl
is undefined.