javascript - AngularJS Controller is not a function error -


i'm getting error when adding ng-controller="headercontroller" div.

error: ng:areq bad argument argument 'headercontroller' not function, got undefined 

my html looks that:

<div ng-app="myapp">     <div ng-controller="headercontroller">     </div>     <div ng-controller="postcontroller">     </div> </div> 

also include following files:

myapp.js

var myapp = angular.module('myapp', ['postservices', 'angularfileupload', 'ngsanitize', 'ui.date', 'bootstraplightbox', 'profileservices']); 

headercontroller.js

myapp.controller('headercontroller', ['$scope', 'postservices', '$http', function($scope, postservices, $http) {     $scope.getbookmarkscount = function() {         postservices.getbookmarkscount().then(function(response) {             if (response.data.status == 'success') {                 $scope.bookmarkscount = response.data.bookmarkscount;             } else {                 $scope.errormessage = response.data.message;             }         })     }; }]); 

postcontroller.js beggining of file looks like:

   myapp.controller('postcontroller', ['$scope', 'postservices', '$http', 'fileuploader', 'lightbox',function($scope, postservices, $http, fileuploader, lightbox) { 

postservice.js contains module named postservices , contains service postservices:

angular.module('postservices', [])     .service('postservices', ['$http', function($http) { 

if delete ng-controller="headercontroller" works fine.

does knows problem?

i don't know version of angular use , took 1.4.0 plunk example , try limit code provide see if recreated error.

i had deal more scripts inclusion order. created error. right order in order make work is

<link rel="stylesheet" href="style.css"> <script src="//code.angularjs.org/1.4.0/angular.js"></script> <script src="myapp.js"></script>   <script src="postcontroller.js"></script> <script src="postservice.js"></script> <script src="headercontroller.js"></script> 

http://plnkr.co/edit/nhzqfmi1s9r98uamzwyg

so main point defined postservice.js before headercontroller


Comments

Popular posts from this blog

javascript - gulp-nodemon - nodejs restart after file change - Error: listen EADDRINUSE events.js:85 -

Fatal Python error: Py_Initialize: unable to load the file system codec. ImportError: No module named 'encodings' -

javascript - oscilloscope of speaker input stops rendering after a few seconds -