gpt4 book ai didi

javascript - 错误: [$injector:unpr] Unknown provider: a

转载 作者:行者123 更新时间:2023-12-02 16:45:08 24 4
gpt4 key购买 nike

这是我的代码:

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

})
});

});

我收到以下错误:

Error: [$injector:unpr] Unknown provider: assignmentAttachmentsProvider <- assignmentAttachments http://errors.angularjs.org/1.2.27/$injector/unpr?p0=assignmentAttachmentsProvider%20%3C-%20assignmentAttachments

最佳答案

确保您已导入注册了 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_;
}));
});

关于javascript - 错误: [$injector:unpr] Unknown provider: a,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27162466/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com