【问题标题】:Error: [$injector:unpr] Unknown provider: a错误:[$injector:unpr] 未知提供者:a
【发布时间】:2015-01-25 13:36:24
【问题描述】:

这是我的代码:

app.factory('assignmentAttachments', function() {


});

describe("test", function() {
    // arrange variable
    var assignmentAttachments;

    // inject service
     beforeEach(inject(function(_assignmentAttachments_) {
        assignmentAttachments = _assignmentAttachments_;
     })); 

    describe("test", function() {
        it("test", function() {
            // arrange

        })
    });

});

我收到以下错误:

错误:[$injector:unpr] 未知提供者: assignmentAttachmentsProvider http://errors.angularjs.org/1.2.27/$injector/unpr?p0=assignmentAttachmentsProvider%20%3C-%20assignmentAttachments

【问题讨论】:

    标签: javascript angularjs jasmine


    【解决方案1】:

    确保您已导入注册assignmentAttachments 的模块。比如assignmentAttachments注册在app模块中,像这样:

    var app = angular.module('app', [])
    app.factory('assignmentAttachments', ...});
    

    然后你必须在测试中导入那个模块:

    describe("test", function() {
        ...
    
        beforeEach(module('app')); // <== add this line
    
        // inject service
        beforeEach(inject(function(_assignmentAttachments_) {
            assignmentAttachments = _assignmentAttachments_;
        })); 
    });
    

    【讨论】:

      猜你喜欢
      • 2017-04-25
      • 1970-01-01
      • 1970-01-01
      • 2016-03-26
      • 2014-07-19
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多