未知提供者:$provideProvider angularjs 茉莉花
Unknown provider: $provideProvider angularjs jasmine
我收到此错误:"Error: [$injector:unpr] Unknown provider: $provideProvider <- $provide"。我被困了几个小时谷歌搜索。我见过很多这样的例子,但我不确定该怎么做。
"use strict";
describe('Controller: ProfileCtrl', function ($provide) {
//load the controller's module
var mockProfileFactory;
beforeEach(function() {
module('profileUpdate', function($provide) {
mockProfileFactory = {
get: function() {
id: 16
}
};
$provide.value('Profile', mockProfileFactory);
});
var ProfileCtrl;
var scope;
inject(function ($controller, $rootScope, $provide) {
scope = $rootScope.$new();
ProfileCtrl = $controller('ProfileCtrl', {
$scope: scope
});
});
});
it('should have 3 items', function() {
var things = scope.range(1,3,1);
expect(things).toBe(3);
});
});
$provide 是provider,只能在app.config方法中注入$provide,不能在
控制器方法。
您获得了一些奖励。特别是注入语句中的那个。你不能注入提供,它只对模块可用。尝试下面的更改。
"use strict";
// SEE no provide here
describe('Controller: ProfileCtrl', function () {
//load the controller's module
var mockProfileFactory;
beforeEach(function() {
module('profileUpdate', function($provide) {
mockProfileFactory = {
get: function() {
id: 16
}
};
$provide.value('Profile', mockProfileFactory);
});
var ProfileCtrl;
var scope;
// SEE and neither in the inject here
inject(function ($controller, $rootScope) {
scope = $rootScope.$new();
ProfileCtrl = $controller('ProfileCtrl', {
$scope: scope
});
});
});
it('should have 3 items', function() {
var things = scope.range(1,3,1);
expect(things).toBe(3);
});
});
阅读 angularjs 提供商的概念,并根据本指南检查您的代码:
我收到此错误:"Error: [$injector:unpr] Unknown provider: $provideProvider <- $provide"。我被困了几个小时谷歌搜索。我见过很多这样的例子,但我不确定该怎么做。
"use strict";
describe('Controller: ProfileCtrl', function ($provide) {
//load the controller's module
var mockProfileFactory;
beforeEach(function() {
module('profileUpdate', function($provide) {
mockProfileFactory = {
get: function() {
id: 16
}
};
$provide.value('Profile', mockProfileFactory);
});
var ProfileCtrl;
var scope;
inject(function ($controller, $rootScope, $provide) {
scope = $rootScope.$new();
ProfileCtrl = $controller('ProfileCtrl', {
$scope: scope
});
});
});
it('should have 3 items', function() {
var things = scope.range(1,3,1);
expect(things).toBe(3);
});
});
$provide 是provider,只能在app.config方法中注入$provide,不能在 控制器方法。
您获得了一些奖励。特别是注入语句中的那个。你不能注入提供,它只对模块可用。尝试下面的更改。
"use strict";
// SEE no provide here
describe('Controller: ProfileCtrl', function () {
//load the controller's module
var mockProfileFactory;
beforeEach(function() {
module('profileUpdate', function($provide) {
mockProfileFactory = {
get: function() {
id: 16
}
};
$provide.value('Profile', mockProfileFactory);
});
var ProfileCtrl;
var scope;
// SEE and neither in the inject here
inject(function ($controller, $rootScope) {
scope = $rootScope.$new();
ProfileCtrl = $controller('ProfileCtrl', {
$scope: scope
});
});
});
it('should have 3 items', function() {
var things = scope.range(1,3,1);
expect(things).toBe(3);
});
});
阅读 angularjs 提供商的概念,并根据本指南检查您的代码: