未知的提供程序︰ $provideProvider angularjs 茉莉花

标签: AngularJS
发布时间: 2017/4/29 2:40:38
注意事项: 本文中文内容可能为机器翻译,如要查看英文原文请点击上面连接.

我得到这个错误:"错误: [$injector: unpr] 未知的提供程序︰ $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);
});

});

解决方法 1:

你有几个奖金提供。尤其是在插入语句中。你不能注入提供,它是唯一可到模块。试一试我的更改下面。

"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 提供程序概念,并且还检查代码免受本指南︰

http://nathanleclaire.com/blog/2013/12/13/how-to-unit-test-controllers-in-angularjs-without-setting-your-hair-on-fire/

官方微信
官方QQ群
31647020