1

I have sample on Angular JS as:

angular.module('wm-admin', []). config(function($routeProvider) { $routeProvider. when('/users', {controller:UsersController, templateUrl:'/public/html/crm/users/list.html'}). otherwise({redirectTo:'/users'}); }); // Controllers // function UsersController($scope) { } 

It gives me error:

Uncaught Error: [$injector:modulerr] 

So, what I do wrong?

HTML:

<body ng-app="wm-admin"> </body> 

I tried also any code:

Angular JS:

(function (angular) { 'use strict'; angular.module('wm-admin', []) .config(function($routeProvider) { $routeProvider. when('/users', {controller:UsersController, templateUrl:'/public/html/crm/users/list.html'}). otherwise({redirectTo:'/users'}); }) // Controllers // .controller('UsersController', ['$scope', '$http', function ($scope, $http) { }]) })(window.angular); 

Look please code upper

2 Answers 2

2

You haven't injected the controller properly to your app. Add this line:

angular.module('wm-admin').controller('UsersController', UsersController); 

EDIT

In your updated question you have this code:

(function (angular) { 'use strict'; angular.module('wm-admin', []) .config(function($routeProvider) { $routeProvider. when('/users', {controller:UsersController, templateUrl:'/public/html/crm/users/list.html'}). otherwise({redirectTo:'/users'}); }) // Controllers // .controller('UsersController', ['$scope', '$http', function ($scope, $http) { }]) })(window.angular); 

But now UsersController is no longer a function within the scope of the {controller: UsersController} line. Change it to controller: 'UsersController' (string, not reference to a function):

(function (angular) { 'use strict'; angular.module('wm-admin', []) .config(function($routeProvider) { $routeProvider. when('/users', {controller: 'UsersController', templateUrl:'/public/html/crm/users/list.html'}). otherwise({redirectTo:'/users'}); }) // Controllers // .controller('UsersController', ['$scope', '$http', function ($scope, $http) { }]) })(window.angular); 
Sign up to request clarification or add additional context in comments.

Comments

1

You never actually made a controller.

angular .module('wm-admin') .controller('UsersController', UsersController); UsersController.$inject = ['$scope']; function UsersController($scope) { } 

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.