Error: [$ injector: unpr] Unknown provider: $ scopeProvider <- $ scope Error

I get this general error Error: [$injector:unpr] Unknown provider: $scopeProvider <- $scope with my test case. I know this is general, and there are several other threads explaining the solutions. But I really could not come up with an answer to my problem. Can someone point me in the right direction?

ViewMeetingCtrl,

 (function () { 'use strict'; angular.module('MyApp').controller('ViewMeetingCtrl', ViewMeetingCtrl); ViewMeetingCtrl.$inject = ['$scope', '$state', '$http', '$translate', 'notificationService', 'meetingService', '$modal', 'meeting', 'attachmentService']; function ViewMeetingCtrl($scope, $state, $http, $translate, notificationService, meetingService, $modal, meeting, attachmentService) { $scope.meeting = meeting; $scope.test = "testvalue"; if (meeting.Status == 'Cancelled') { $scope.actionButtons = false; } else { $scope.actionButtons = true; } //more code } })(); 

MeetingCtrlSpec.js

 describe('ViewMeetingCtrl', function () { var $rootScope, scope, $controller, meetingService; beforeEach(angular.mock.module('MyApp')); beforeEach(inject(function ($rootScope, $controller, meetingService) { scope = $rootScope.$new(); $controller('ViewMeetingCtrl', { meetingService: meetingService, '$rootScope' : $rootScope, scope: scope }); })); it('should change greeting value if name value is changed', function () { //some assertion }); }); 

Error tracing:

 Firefox 37.0.0 (Windows 8.1) ViewMeetingCtrl should change greeting value if name value is changed FAILED Error: [$injector:unpr] Unknown provider: $scopeProvider <- $scope <- ViewMeetingCtrl http://errors.angularjs.org/1.3.15/$injector/unpr?p0=%24scopeProvider%20%3C-%20%24scope%20%3C-%20ViewMeetingCtrl minErr/<@C:/Users/dell%20pc/Documents/Work/MyApp/WebApiRole/bower_components/angular/angular.js:63:12 createInjector/providerCache.$injector<@C:/Users/dell%20pc/Documents/Work/MyApp/WebApiRole/bower_components/ang ular/angular.js:4015:19 [email protected] :/Users/dell%20pc/Documents/Work/MyApp/WebApiRole/bower_components/angular/angular.js:4162:39 createInjector/instanceCache.$injector<@C:/Users/dell%20pc/Documents/Work/MyApp/WebApiRole/bower_components/ang ular/angular.js:4020:28 [email protected] :/Users/dell%20pc/Documents/Work/MyApp/WebApiRole/bower_components/angular/angular.js:4162:39 [email protected] :/Users/dell%20pc/Documents/Work/MyApp/WebApiRole/bower_components/angular/angular.js:4194:1 [email protected] :/Users/dell%20pc/Documents/Work/MyApp/WebApiRole/bower_components/angular/angular.js:4211:27 $ControllerProvider/this.$get</<@C:/Users/dell%20pc/Documents/Work/MyApp/WebApiRole/bower_components/angular/an gular.js:8501:18 angular.mock.$ControllerDecorator</<@C:/Users/dell%20pc/Documents/Work/MyApp/WebApiRole/node_modules/angular-mo cks/angular-mocks.js:1878:12 @C:/Users/dell pc/Documents/Work/MyApp/FLIS.Client.Tests/test/company/MeetingCtrlSpec.js:8:1 [email protected] :/Users/dell%20pc/Documents/Work/MyApp/WebApiRole/bower_components/angular/angular.js:4203:14 [email protected] :/Users/dell%20pc/Documents/Work/MyApp/WebApiRole/node_modules/angular-mocks/angular-mocks.js:2436:11 [email protected] :/Users/dell%20pc/Documents/Work/MyApp/WebApiRole/node_modules/angular-mocks/angular-mocks .js:2407:25 @C:/Users/dell pc/Documents/Work/MyApp/Client.Tests/test/company/MeetingCtrlSpec.js:6:16 @C:/Users/dell pc/Documents/Work/MyApp/Client.Tests/test/company/MeetingCtrlSpec.js:1:1 Firefox 37.0.0 (Windows 8.1): Executed 3 of 3 (1 FAILED) (0.094 secs / 0.091 secs) 
+6
source share
2 answers

Replace

  $controller('ViewMeetingCtrl', { meetingService: meetingService, '$rootScope' : $rootScope, scope: scope }); 

by

  $controller('ViewMeetingCtrl', { meetingService: meetingService, $scope: scope }); 

A controller must be entered with an argument named $ scope, not with a scope. And $ rootScope is not part of the injected collaborators of your controller.

+6
source

For the same error, I forgot to put '$' before scope in

 app.controller("loginCtrl", function(**$**scope){ }) 
-1
source

Source: https://habr.com/ru/post/988208/


All Articles