错误: [$injector:unpr] 未知提供程序: a.

Error: [$injector:unpr] Unknown provider: a

本文关键字:未知 程序 unpr injector 错误      更新时间:2023-09-26

这是我的代码:

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] 未知提供程序: 分配附件提供程序<- 分配附件 http://errors.angularjs.org/1.2.27/$injector/unpr?p0=assignmentAttachmentsProvider%20%3C-%20assignmentAttachments

确保已导入注册assignmentAttachments的模块。例如,如果在app模块中注册了assignmentAttachments,如下所示:

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_;
    })); 
});