我正在开发AngularJS应用程序,我使用名为angular-ui-tree的第三方库显示数据。
为了使用这个库,我应该将ui.tree
作为dependecny添加到我的主app模块中。我已完成该链接中给出的所有步骤以使用此库。
我已成功使用此库来创建我想要的树。现在我想为我的控制器编写茉莉花规格。
但是在使用这个库之后,我之前的茉莉花规格都没有起作用 所有茉莉花都抛出如下错误。
Error: [$injector:modulerr] Failed to instantiate module CqAdminUiApp due to:
Error: [$injector:modulerr] Failed to instantiate module ui.tree due to:
Error: [$injector:nomod] Module 'ui.tree' is not available! You either misspelled the module name or forgot to load it. If registering a module ensure that you specify the dependencies as the second argument.
http://errors.angularjs.org/1.5.8/$injector/nomod?p0=ui.tree
at http://localhost:8234/webjars/angularjs/1.5.8/angular.js:68:12
at http://localhost:8234/webjars/angularjs/1.5.8/angular.js:2082:17
at ensure (http://localhost:8234/webjars/angularjs/1.5.8/angular.js:2006:38)
at module (http://localhost:8234/webjars/angularjs/1.5.8/angular.js:2080:14)
at http://localhost:8234/webjars/angularjs/1.5.8/angular.js:4617:22
at forEach (http://localhost:8234/webjars/angularjs/1.5.8/angular.js:321:20)
at loadModules (http://localhost:8234/webjars/angularjs/1.5.8/angular.js:4601:5)
at http://localhost:8234/webjars/angularjs/1.5.8/angular.js:4618:40
at forEach (http://localhost:8234/webjars/angularjs/1.5.8/angular.js:321:20)
at loadModules (http://localhost:8234/webjars/angularjs/1.5.8/angular.js:4601:5)
http://errors.angularjs.org/1.5.8/$injector/modulerr?p0=ui.tree&p1=Error%3A%20%5B%24injector%3Anomod%5D%20Module%20'ui.tree'%20is%20not%20available!%20You%20either%20misspelled%20the%20module%20name%20or%20forgot%20to%20load%20it.%20If%20registering%20a%20module%20ensure%20that%20you%20specify%20the%20dependencies%20as%20the%20second%20argument.%0Ahttp%3A%2F%2Ferrors.angularjs.org%2F1.5.8%2F%24injector%2Fnomod%3Fp0%3Dui.tree%0A%20%20%20%20at%20http%3A%2F%2Flocalhost%3A8234%2Fwebjars%2Fangularjs%2F1.5.8%2Fangular.js%3A68%3A12%0A%20%20%20%20at%20http%3A%2F%2Flocalhost%3A8234%2Fwebjars%2Fangularjs%2F1.5.8%2Fangular.js%3A2082%3A17%0A%20%20%20%20at%20ensure%20(http%3A%2F%2Flocalhost%3A8234%2Fwebjars%2Fangularjs%2F1.5.8%2Fangular.js%3A2006%3A38)%0A%20%20%20%20at%20module%20(http%3A%2F%2Flocalhost%3A8234%2Fwebjars%2Fangularjs%2F1.5.8%2Fangular.js%3A2080%3A14)%0A%20%20%20%20at%20http%3A%2F%2Flocalhost%3A8234%2Fwebjars%2Fangularjs%2F1.5.8%2Fangular.js%3A4617%3A22%0A%20%20%20%20at%20forEach%20(http%3A%2F%2Flocalhost%3A8234%2Fwebjars%2Fangularjs%2F1.5.8%2Fangular.js%3A321%3A20)%0A%20%20%20%20at%20loadModules%20(http%3A%2F%2Flocalhost%3A8234%2Fwebjars%2Fangularjs%2F1.5.8%2Fangular.js%3A4601%3A5)%0A%20%20%20%20at%20http%3A%2F%2Flocalhost%3A8234%2Fwebjars%2Fangularjs%2F1.5.8%2Fangular.js%3A4618%3A40%0A%20%20%20%20at%20forEach%20(http%3A%2F%2Flocalhost%3A8234%2Fwebjars%2Fangularjs%2F1.5.8%2Fangular.js%3A321%3A20)%0A%20%20%20%20at%20loadModules%20(http%3A%2F%2Flocalhost%3A8234%2Fwebjars%2Fangularjs%2F1.5.8%2Fangular.js%3A4601%3A5)
at http://localhost:8234/webjars/angularjs/1.5.8/angular.js:68:12
at http://localhost:8234/webjars/angularjs/1.5.8/angular.js:4640:15
at forEach (http://localhost:8234/webjars/angularjs/1.5.8/angular.js:321:20)
at loadModules (http://localhost:8234/webjars/angularjs/1.5.8/angular.js:4601:5)
at http://localhost:8234/webjars/angularjs/1.5.8/angular.js:4618:40
at forEach (http://localhost:8234/webjars/angularjs/1.5.8/angular.js:321:20)
at loadModules (http://localhost:8234/webjars/angularjs/1.5.8/angular.js:4601:5)
at Object.createInjector [as injector] (http://localhost:8234/webjars/angularjs/1.5.8/angular.js:4523:19)
at Object.workFn (http://localhost:8234/webjars/angularjs/1.5.8/angular-mocks.js:3074:52)
at attemptSync (http://localhost:8234/webjars/jasmine/2.5.1/lib/jasmine-core/jasmine.js:1942:24)
http://errors.angularjs.org/1.5.8/$injector/modulerr?p0=CqAdminUiApp&p1=Error%3A%20%5B%24injector%3Amodulerr%5D%20Failed%20to%20instantiate%20module%20ui.tree%20due%20to%3A%0AError%3A%20%5B%24injector%3Anomod%5D%20Module%20'ui.tree'%20is%20not%20available!%20You%20either%20misspelled%20the%20module%20name%20or%20forgot%20to%20load%20it.%20If%20registering%20a%20module%20ensure%20that%20you%20specify%20the%20dependencies%20as%20the%20second%20argument.%0Ahttp%3A%2F%2Ferrors.angularjs.org%2F1.5.8%2F%24injector%2Fnomod%3Fp0%3Dui.tree%0A%20%20%20%20at%20http%3A%2F%2Flocalhost%3A8234%2Fwebjars%2Fangularjs%2F1.5.8%2Fangular.js%3A68%3A12%0A%20%20%20%20at%20http%3A%2F%2Flocalhost%3A8234%2Fwebjars%2Fangularjs%2F1.5.8%2Fangular.js%3A2082%3A17%0A%20%20%20%20at%20ensure%20(http%3A%2F%2Flocalhost%3A8234%2Fwebjars%2Fangularjs%2F1.5.8%2Fangular.js%3A2006%3A38)%0A%20%20%20%20at%20module%20(http%3A%2F%2Flocalhost%3A8234%2Fwebjars%2Fangularjs%2F1.5.8%2Fangular.js%3A2080%3A14)%0A%20%20%20%20at%20http%3A%2F%2Flocalhost%3A8234%2Fwebjars%2Fangularjs%2F1.5.8%2Fangular.js%3A4617%3A22%0A%20%20%20%20at%20forEach%20(http%3A%2F%2Flocalhost%3A8234%2Fwebjars%2Fangularjs%2F1.5.8%2Fangular.js%3A321%3A20)%0A%20%20%20%20at%20loadModules%20(http%3A%2F%2Flocalhost%3A8234%2Fwebjars%2Fangularjs%2F1.5.8%2Fangular.js%3A4601%3A5)%0A%20%20%20%20at%20http%3A%2F%2Flocalhost%3A8234%2Fwebjars%2Fangularjs%2F1.5.8%2Fangular.js%3A4618%3A40%0A%20%20%20%20at%20forEach%20(http%3A%2F%2Flocalhost%3A8234%2Fwebjars%2Fangularjs%2F1.5.8%2Fangular.js%3A321%3A20)%0A%20%20%20%20at%20loadModules%20(http%3A%2F%2Flocalhost%3A8234%2Fwebjars%2Fangularjs%2F1.5.8%2Fangular.js%3A4601%3A5)%0Ahttp%3A%2F%2Ferrors.angularjs.org%2F1.5.8%2F%24injector%2Fmodulerr%3Fp0%3Dui.tree%26p1%3DError%253A%2520%255B%2524injector%253Anomod%255D%2520Module%2520'ui.tree'%2520is%2520not%2520available!%2520You%2520either%2520misspelled%2520the%2520module%2520name%2520or%2520forgot%2520to%2520load%2520it.%2520If%2520registering%2520a%2520module%2520ensure%2520that%2520you%2520specify%2520the%2520dependencies%2520as%2520the%2520second%2520argument.%250Ahttp%253A%252F%252Ferrors.angularjs.org%252F1.5.8%252F%2524injector%252Fnomod%253Fp0%253Dui.tree%250A%2520%2520%2520%2520at%2520http%253A%252F%252Flocalhost%253A8234%252Fwebjars%252Fangularjs%252F1.5.8%252Fangular.js%253A68%253A12%250A%2520%2520%2520%2520at%2520http%253A%252F%252Flocalhost%253A8234%252Fwebjars%252Fangularjs%252F1.5.8%252Fangular.js%253A2082%253A17%250A%2520%2520%2520%2520at%2520ensure%2520(http%253A%252F%252Flocalhost%253A8234%252Fwebjars%252Fangularjs%252F1.5.8%252Fangular.js%253A2006%253A38)%250A%2520%2520%2520%2520at%2520module%2520(http%253A%252F%252Flocalhost%253A8234%252Fwebjars%252Fangularjs%252F1.5.8%252Fangular.js%253A2080%253A14)%250A%2520%2520%2520%2520at%2520http%253A%252F%252Flocalhost%253A8234%252Fwebjars%252Fangularjs%252F1.5.8%252Fangular.js%253A4617%253A22%250A%2520%2520%2520%2520at%2520forEach%2520(http%253A%252F%252Flocalhost%253A8234%252Fwebjars%252Fangularjs%252F1.5.8%252Fangular.js%253A321%253A20)%250A%2520%2520%2520%2520at%2520loadModules%2520(http%253A%252F%252Flocalhost%253A8234%252Fwebjars%252Fangularjs%252F1.5.8%252Fangular.js%253A4601%253A5)%250A%2520%2520%2520%2520at%2520http%253A%252F%252Flocalhost%253A8234%252Fwebjars%252Fangularjs%252F1.5.8%252Fangular.js%253A4618%253A40%250A%2520%2520%2520%2520at%2520forEach%2520(http%253A%252F%252Flocalhost%253A8234%252Fwebjars%252Fangularjs%252F1.5.8%252Fangular.js%253A321%253A20)%250A%2520%2520%2520%2520at%2520loadModules%2520(http%253A%252F%252Flocalhost%253A8234%252Fwebjars%252Fangularjs%252F1.5.8%252Fangular.js%253A4601%253A5)%0A%20%20%20%20at%20http%3A%2F%2Flocalhost%3A8234%2Fwebjars%2Fangularjs%2F1.5.8%2Fangular.js%3A68%3A12%0A%20%20%20%20at%20http%3A%2F%2Flocalhost%3A8234%2Fwebjars%2Fangularjs%2F1.5.8%2Fangular.js%3A4640%3A15%0A%20%20%20%20at%20forEach%20(http%3A%2F%2Flocalhost%3A8234%2Fwebjars%2Fangularjs%2F1.5.8%2Fangular.js%3A321%3A20)%0A%20%20%20%20at%20loadModules%20(http%3A%2F%2Flocalhost%3A8234%2Fwebjars%2Fangularjs%2F1.5.8%2Fangular.js%3A4601%3A5)%0A%20%20%20%20at%20http%3A%2F%2Flocalhost%3A8234%2Fwebjars%2Fangularjs%2F1.5.8%2Fangular.js%3A4618%3A40%0A%20%20%20%20at%20forEach%20(http%3A%2F%2Flocalhost%3A8234%2Fwebjars%2Fangularjs%2F1.5.8%2Fangular.js%3A321%3A20)%0A%20%20%20%20at%20loadModules%20(http%3A%2F%2Flocalhost%3A8234%2Fwebjars%2Fangularjs%2F1.5.8%2Fangular.js%3A4601%3A5)%0A%20%20%20%20at%20Object.createInjector%20%5Bas%20injector%5D%20(http%3A%2F%2Flocalhost%3A8234%2Fwebjars%2Fangularjs%2F1.5.8%2Fangular.js%3A4523%3A19)%0A%20%20%20%20at%20Object.workFn%20(http%3A%2F%2Flocalhost%3A8234%2Fwebjars%2Fangularjs%2F1.5.8%2Fangular-mocks.js%3A3074%3A52)%0A%20%20%20%20at%20attemptSync%20(http%3A%2F%2Flocalhost%3A8234%2Fwebjars%2Fjasmine%2F2.5.1%2Flib%2Fjasmine-core%2Fjasmine.js%3A1942%3A24)
at http://localhost:8234/webjars/angularjs/1.5.8/angular.js:68:12
at http://localhost:8234/webjars/angularjs/1.5.8/angular.js:4640:15
at forEach (http://localhost:8234/webjars/angularjs/1.5.8/angular.js:321:20)
at loadModules (http://localhost:8234/webjars/angularjs/1.5.8/angular.js:4601:5)
at Object.createInjector [as injector] (http://localhost:8234/webjars/angularjs/1.5.8/angular.js:4523:19)
at Object.workFn (http://localhost:8234/webjars/angularjs/1.5.8/angular-mocks.js:3074:52)
at attemptSync (http://localhost:8234/webjars/jasmine/2.5.1/lib/jasmine-core/jasmine.js:1942:24)
at QueueRunner.run (http://localhost:8234/webjars/jasmine/2.5.1/lib/jasmine-core/jasmine.js:1930:9)
at QueueRunner.execute (http://localhost:8234/webjars/jasmine/2.5.1/lib/jasmine-core/jasmine.js:1915:10)
at Spec.queueRunnerFactory (http://localhost:8234/webjars/jasmine/2.5.1/lib/jasmine-core/jasmine.js:710:35)
CqAdminUiApp routing should proceed to /Jobs on requests to /Jobs when logged in
前几行表示模块ui.tree
可能尚未添加为主应用程序模块的依赖项。但我确保它已被添加。
我在stackoverflow上发现了关于此错误的其他几篇帖子,但他们都谈到将缺少的模块添加为我已经完成的主应用程序的依赖。
我很惊讶我仍然得到同样的错误
Blow是代码片段。
我的主要应用模块:
(function () {
'use strict';
var MyUiApp = angular.module('MyUiApp', [
'ngRoute',
'ngAnimate',
'ngCookies',
'ui.bootstrap',
'ui.tree',
'chart.js',
]);
MyApp.config(['$routeProvider', function ($routeProvider) {
$routeProvider.
when('/Authenticate', {
templateUrl: 'app/views/authenticate.html',
controller: 'authenticationController'
}).
// configuration for other urls.
}]);
}());
的index.html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="ISO-8859-1">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="shortcut icon" type="image/png" href="assets/image/favicon.png"/>
<link rel="stylesheet" href="webjars/bootstrap/3.3.7/css/bootstrap.min.css">
<link rel="stylesheet" href="webjars/bootstrap/3.3.7/css/bootstrap-theme.min.css">
<link rel="stylesheet" href="webjars/angular-chart.js/0.8.8/angular-chart.css">
<link rel="stylesheet" href="webjars/angular-ui-grid/3.2.1/ui-grid.min.css">
<link rel="stylesheet" href="assets/css/derp.css">
<link rel="stylesheet" href="assets/css/spinner.css">
<link rel="stylesheet" href="assets/css/blur.css">
<link rel="stylesheet" href="assets/css/angular-ui-tree.min.css">
<script src="webjars/angularjs/1.5.8/angular.min.js"></script>
<script src="webjars/angularjs/1.5.8/angular-route.min.js"></script>
<script src="webjars/angularjs/1.5.8/angular-animate.min.js"></script>
<script src="webjars/angularjs/1.5.8/angular-cookies.min.js"></script>
<script src="webjars/angular-base64/2.0.5/angular-base64.min.js"></script>
<script src="webjars/angular-ui-bootstrap/0.14.3/ui-bootstrap-tpls.min.js"></script>
<script src="webjars/favico.js/0.3.10/favico-0.3.10.min.js"></script>
<script src="webjars/chartjs/2.1.3/Chart.min.js"></script>
<script src="webjars/angular-chart.js/0.8.8/angular-chart.min.js"></script>
<script src="webjars/angular-ui-grid/3.2.1/ui-grid.min.js"></script>
<script src="assets/js/angular-ui-tree.js"></script> // This js file is required for ui-tree
//Other files
</head>
<body ng-app="CqAdminUiApp">
<div ng-controller="indexController">
<div id="wrapper">
<div id="sidebar-wrapper">
<ul class="sidebar-nav">
<li class="sidebar-brand">Continuous Quality</li>
<li><a href="#link1">link1</a></li>
<li><a href="#link2">Link2</a></li>
<li><a href="#link3">Link3</a></li>
<li><a href="#link4">Link4</a></li
<li><a href="#Logout">* Logout *</a></li>
</ul>
</div>
<div id="page-content-wrapper">
<div ng-view class="explode-animation"></div>
</div>
</div>
</div>
</body>
</html>
我正在使用茉莉花规格。 spec-runner.html如下。
SPEC-runner.html
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Derp-o-meter v1.0</title>
<link rel="shortcut icon" type="image/png" href="assets/image/favicon.png">
<link rel="stylesheet" href="../webjars/jasmine/2.5.1/lib/jasmine-core/jasmine.css">
<script src="../webjars/jasmine/2.5.1/lib/jasmine-core/jasmine.js"></script>
<script src="../webjars/jasmine/2.5.1/lib/jasmine-core/jasmine-html.js"></script>
<script src="../webjars/jasmine/2.5.1/lib/jasmine-core/boot.js"></script>
<script src="../webjars/angularjs/1.5.8/angular.js"></script>
<script src="../webjars/angularjs/1.5.8/angular-mocks.js"></script>
<script src="../webjars/angularjs/1.5.8/angular-route.js"></script>
<script src="../webjars/angularjs/1.5.8/angular-animate.js"></script>
<script src="../webjars/angular-base64/2.0.5/angular-base64.js"></script>
<script src="../webjars/angularjs/1.5.8/angular-cookies.min.js"></script>
<script src="../webjars/angular-ui-bootstrap/0.14.3/ui-bootstrap-tpls.min.js"></script>
<script src="../webjars/favico.js/0.3.10/favico-0.3.10.min.js" ></script>
<script src="../webjars/chartjs/2.1.3/Chart.min.js"></script>
<script src="../webjars/angular-chart.js/0.8.8/angular-chart.min.js"></script>
<script src="../webjars/angular-ui-grid/3.2.1/ui-grid.min.js"></script>
<script src="../assets/js/angular-ui-tree.js"></script> // This is the js file needed for ui-tree
<!-- include source files here... -->
<script src="../app/services/authenticationService.js"></script>
<script src="../app/services/eventsService.js"></script>
<script src="../app/controllers/eventsController.js"></script>
<script src="../app/controllers/indexController.js"></script>
<!-- include spec files here... -->
<script src="spec/controllers/eventsController-spec.js"></script>
<script src="spec/controllers/jobsController-spec.js"></script>
// other spec files
<body>
</body>
</html>
其中一个茉莉花规格文件 spec.js
describe('eventsController', function() {
var scope, mockMyService;
beforeEach(function() {
angular.mock.module('my.services');
angular.mock.module('my.controllers');
angular.mock.module('mock.my.services');
});
beforeEach(inject(function($controller, $rootScope, _mockMyService_) {
scope = $rootScope.$new();
mockMyService = _mockEventsService_;
$controller('myController', {
myService: mockMyService,
$scope: scope
});
}));
it('should fetch products', function() {
scope.$apply();
expect(scope.products[0]).toBe("bat");
expect(scope.products[1]).toBe("ball");
});
});
有人可以帮助我摆脱上述错误。
答案 0 :(得分:0)
我遇到了完全相同的问题,而我的问题与 karma.conf.js 中缺少依赖项有关:
// Karma configuration
// http://karma-runner.github.io/0.10/config/configuration-file.html
'use strict';
// ...
module.exports = function(config) {
config.set({
// base path, that will be used to resolve files and exclude
basePath: '../../..',
// testing framework to use (jasmine/mocha/qunit/...)
frameworks: ['jasmine'],
// list of files / patterns to load in the browser
files: [
'src/main/resources/webapp/lib/jquery/jquery.js',
'src/main/resources/webapp/lib/angular/angular.js',
// !!! This was missing:
'src/main/resources/webapp/lib/angular-ui-tree/dist/angular-ui-tree.js'
'src/main/resources/webapp/app/*.js',
'src/main/resources/webapp/app/**/*.js',
],
...
});
};