AngularJS: Register Controller from separate .js file -
i new angularjs , using plnkr.co learn how use angular. have having difficulty registering controller stored in separate .js module initialized. can tell me why below not work?
index.html file
<!doctype html> <html ng-app="plunker"> <head> <meta charset="utf-8" /> <title>angularjs plunker</title> <script> document.write('<base href="' + document.location + '" />'); </script> <link rel="stylesheet" href="style.css" /> <script data-require="angular.js@1.4.x" src="https://cdnjs.cloudflare.com/ajax/libs/angular.js/1.4.6/angular.min.js" data-semver="1.4.6"></script> <script src="app.js"></script> <script scr="mainctrl.js"></script> </head> <body ng-controller="mainctrl"> <p>hello {{name}}!</p> </body> </html>
app.js file
angular.module('plunker', []);
mainctrl.js file
angular.module('plunker') .controller('mainctrl', ['$scope', function($scope) { $scope.name = 'github'; }]);
for me, produces argument 'mainctrl' not function, got undefined.
replace
<script scr="mainctrl.js"></script>
with
<script src="mainctrl.js"></script>
because of typo (scr
instead of src
), source file holding mainctrl
not loaded, therefore mainctrl
undefined.
Comments
Post a Comment