javascript 未知提供者:$rootscopeProvider <- $rootscope
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/15708300/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-27 01:48:23 来源:igfitidea点击:
Unknown provider: $rootscopeProvider <- $rootscope
提问by BanksySan
I'm trying to inject $scope
into a jasmine test, but get the exception
我正在尝试注入$scope
茉莉花测试,但出现异常
Unknown provider: $rootscopeProvider <- $rootscope
My Spec file is this:
我的规范文件是这样的:
describe("with data returned from NormDefinitions API", function () {
const dummyData = [
{"Id": 1, "Name": "Name 1", "Description": "Description 1"},
{"Id": 2, "Name": "Name 2", "Description": "Description 1"}
];
var $scope,
mockService = {
query: function () {
return dummyData;
}
};
beforeEach(inject(function ($rootscope) {
$scope = $rootscope.$new();
}));
it("it can be instantiated", inject(function($controller) {
var controller = $controller("NormDefinitionsController",
{
$scope: $scope,
myService : mockService
});
expect(controller).not.toBeNull();
}));
});
What am I missing?
我错过了什么?
THanks
谢谢
Dave
戴夫
回答by Mark Rajcok
Typo (happens to all of us): $rootScope
with a capital S
.
错别字(发生在我们所有人身上): $rootScope
大写S
.
Sometimes people forget to inject it. Then you'd get this error:
有时人们会忘记注射它。然后你会得到这个错误:
ReferenceError: $rootScope is not defined