Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Error: [$controller:ctrlreg] The controller with the name 'CounterController' is not registered.

Tags:

angularjs

I see this error when I press F12 in chrome. There seems to be no problems.

My html code

<ul class="dropdown-menu" role="menu" ng-controller="CounterController">
   <li ng-repeat="item in messages"><a href="">{{item.name}}</a></li>
</ul>

Here is my js file. Any idea why? The version of angualr I am using is 1.6.1 angular controller code

angular
.module('myApp.counter_controller', [])
.controller('CounterController', ['$scope', '$filter', function($scope, $filter) {
    'use strict';
    $scope.messages = [{
        name : 'ENG',
        read : false
    }, {
        name : 'JPN',
        read : false
    }, {
        name : 'CHI',
        read : false
    }, ];   
$scope.setRead = function(item, $event) {
  $event.preventDefault();
  $event.stopPropagation();
  item.read = true;
};
$scope.setUnread = function(item, $event) {
  $event.preventDefault();
  $event.stopPropagation();
  item.read = false;
};
$scope.setReadAll = function($event) {
  $event.preventDefault();
  $event.stopPropagation();
  angular.forEach($scope.messages, function(item) {
    item.read = true;
  });
};
$scope.unseenCount = $filter('filter')($scope.messages, {
  read: false
}).length;
$scope.$watch('messages', function(messages) {
  $scope.unseenCount = $filter('filter')(messages, {
    read: false
  }).length;
}, true);
}]);
like image 696
Navneet vaghasiya Avatar asked Jan 21 '17 14:01

Navneet vaghasiya


Video Answer


2 Answers

You may have done some file arranging problem.

please see code it is working fine :code link

output:Main Output

like image 145
Hamid Raza Noori Avatar answered Sep 21 '22 11:09

Hamid Raza Noori


you may need to wrap them in an anonymous function like so

(function(){                                                                     
    var myApp = angular.module('myAPP', ['ngRoute']);

   storehubs.controller('welcome',['$scope',function($scope){
       $scope.pageClass="welcome_page";
   }]);
})();

Also your html should include ng-app="myApp" and your links to angular.min.js and yourapp.js files need to be in the head tag of your html.

Look at some docs https://docs.angularjs.org/guide/controller

like image 29
Samuel Kwame Antwi Avatar answered Sep 21 '22 11:09

Samuel Kwame Antwi