Error: [$injector:unpr] Unknown provider: $scopeProvider <- $scope Error
Error: [$injector:unpr] Unknown provider: $scopeProvider <- $scope Error
我在测试用例中收到此常见错误错误:[$injector:unpr] Unknown provider: $scopeProvider <- $scope
。我知道这是一个常见的问题,并且很少有其他线程用解决方案进行解释。但我真的想不出我的问题的答案。谁能指出我正确的方向?
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
});
});
错误跟踪:
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
getService@C:/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
getService@C:/Users/dell%20pc/Documents/Work/MyApp/WebApiRole/bower_components/angular/angular.js:4162:39
invoke@C:/Users/dell%20pc/Documents/Work/MyApp/WebApiRole/bower_components/angular/angular.js:4194:1
instantiate@C:/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
invoke@C:/Users/dell%20pc/Documents/Work/MyApp/WebApiRole/bower_components/angular/angular.js:4203:14
workFn@C:/Users/dell%20pc/Documents/Work/MyApp/WebApiRole/node_modules/angular-mocks/angular-mocks.js:2436:11
angular.mock.inject@C:/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)
替换
$controller('ViewMeetingCtrl', {
meetingService: meetingService,
'$rootScope' : $rootScope,
scope: scope
});
来自
$controller('ViewMeetingCtrl', {
meetingService: meetingService,
$scope: scope
});
控制器必须注入一个名为 $scope 的参数,而不是 scope。并且 $rootScope 不是您控制器的注入协作者的一部分。
同样的错误,我忘记在
中的 scope
之前放置 '$'
app.controller("loginCtrl", function(**$**scope){
})
我在测试用例中收到此常见错误错误:[$injector:unpr] Unknown provider: $scopeProvider <- $scope
。我知道这是一个常见的问题,并且很少有其他线程用解决方案进行解释。但我真的想不出我的问题的答案。谁能指出我正确的方向?
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
});
});
错误跟踪:
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
getService@C:/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
getService@C:/Users/dell%20pc/Documents/Work/MyApp/WebApiRole/bower_components/angular/angular.js:4162:39
invoke@C:/Users/dell%20pc/Documents/Work/MyApp/WebApiRole/bower_components/angular/angular.js:4194:1
instantiate@C:/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
invoke@C:/Users/dell%20pc/Documents/Work/MyApp/WebApiRole/bower_components/angular/angular.js:4203:14
workFn@C:/Users/dell%20pc/Documents/Work/MyApp/WebApiRole/node_modules/angular-mocks/angular-mocks.js:2436:11
angular.mock.inject@C:/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)
替换
$controller('ViewMeetingCtrl', {
meetingService: meetingService,
'$rootScope' : $rootScope,
scope: scope
});
来自
$controller('ViewMeetingCtrl', {
meetingService: meetingService,
$scope: scope
});
控制器必须注入一个名为 $scope 的参数,而不是 scope。并且 $rootScope 不是您控制器的注入协作者的一部分。
同样的错误,我忘记在
中的scope
之前放置 '$'
app.controller("loginCtrl", function(**$**scope){
})