gpt4 book ai didi

javascript - 使用 Angular js 对几乎所有内容进行分页,无法实例化模块错误

转载 作者:行者123 更新时间:2023-12-03 09:37:51 26 4
gpt4 key购买 nike

我正在尝试向我的 Angular Js 应用程序添加此链接( http://www.michaelbromley.co.uk/blog/108/paginate-almost-anything-in-angularjs )中包含的分页 Angular JS 模块,该模块与 How to do paging in AngularJS? 连接。 .

按照这些步骤,我已将模块的 javascript 文件包含到 index.html 中,并将模块的依赖项添加到模块的声明中。我是 angularJS 的新手,我确信我一定错过了一些基本的东西。错误是:

Uncaught Error: [$injector:modulerr] Failed to instantiate module myApp due to:
Error: [ng:areq] Argument 'fn' is not a function, got string
http://errors.angularjs.org/1.2.9/ng/areq?p0=fn&p1=not%20a%20function%2C%20got%20string
at http://127.0.0.1/sessions-angularJs-...

HTML(INDEX.HTML)

<!doctype html>
<html lang="en" ng-app="myApp">
<head>
<meta charset="utf-8">
<title>My AngularJS App</title>
<link rel="stylesheet" href="css/app.css"/>
<link rel="stylesheet" href="css/taskman.css"/>
<script src="lib/angular/angular.js"></script>

<script src="js/app.js"></script>
<script src="lib/angular/angular-route.js"></script>
<script src="lib/angular/dirPagination.js"></script>
<script src="js/directives/loginDrc.js"></script>
<script src="js/services/loginService.js"></script>
<script src="js/controllers/priceCtrl.js"></script>
<script src="js/services/sessionService.js"></script>
<script src="js/controllers/loginCtrl.js"></script>
<script src="js/controllers/homeCtrl.js"></script>
<script src="js/controllers/campCtrl.js"></script>
<script src="js/controllers/quizCtrl.js"></script>
<script src="js/controllers/voucherCtrl.js"></script>
<script src="//code.jquery.com/jquery-1.11.2.min.js"></script>
</head>
<body>
<div class="navbar navbar-default" id="navbar">
<div class="container">
<div class="navbar-header">
<a class="navbar-brand" href="/">Campaigning Framework</a>
</div>
<ul class="nav navbar-nav navbar-right" ng-controller="homeCtrl">
<li><a href="#"><i class="fa fa-home"></i> Home</a></li>
<li><a href="#voucher"><i class="fa fa-comment"></i> Vouchers</a></li>
<li><a href="#campaign"><i class="fa fa-shield"></i> Campaign</a></li>
<li><a href="#quiz"><i class="fa fa-shield"></i> Quiz</a></li>
<li><a href="#price"><i class="fa fa-shield"></i> Prize</a></li>
<li><a href="" ng-click="logout()"><i class="fa fa-comment"></i> Logout</a></li>
</ul>
</div>
</div>
<div ng-view>

</div>

<!-- In production use:
<script src="//ajax.googleapis.com/ajax/libs/angularjs/1.0.7/angular.min.js"></script>
-->



</body>
</html>

JAVASCRIPT (APP.JS)

'use strict';
// Declare app level module which depends on filters, and services
var app= angular.module('myApp', ['ngRoute'], ['angularUtils.directives.dirPagination']);
//var app= angular.module('myApp', ['ngRoute'], ['angularUtils.directives.dirPagination']);
app.config(['$routeProvider', function($routeProvider) {
$routeProvider.when('/login', {templateUrl: 'partials/login.html', controller: 'loginCtrl'});
$routeProvider.when('/voucher', {templateUrl: 'partials/voucher.html', controller: 'voucherCtrl'});
$routeProvider.when('/home', {templateUrl: 'partials/home.html', controller: 'homeCtrl'});
$routeProvider.when('/campaign', {templateUrl: 'partials/campaign.html', controller: 'campCtrl'});
$routeProvider.when('/quiz', {templateUrl: 'partials/quiz.html', controller: 'quizCtrl'});
$routeProvider.when('/price', {templateUrl: 'partials/price.html', controller: 'priceCtrl'});
$routeProvider.otherwise({redirectTo: '/login'});
}]);
app.filter('range', function() {
return function(input, total) {
total = parseInt(total);
for (var i=1 ; i<=total; i++)
if(i %10 == 0){
input.push(i);
}
return input;
};
});


app.run(function($rootScope, $location, loginService){
var routespermission=['/home', '/campaign', '/quiz', '/price', '/voucher']; //route that require login
$rootScope.$on('$routeChangeStart', function(){
if( routespermission.indexOf($location.path()) !=-1)
{
var connected=loginService.islogged();
connected.then(function(msg){
if(!msg.data) $location.path('/login');
});
}
});
});

最佳答案

问题在于模块声明,依赖项需要在一个数组中传递,而不是像我那样在两个数组中传递。

var app= angular.module('myApp', ['ngRoute'], ['angularUtils.directives.dirPagination']);

应该是:

var app= angular.module('myApp', ['ngRoute', 'angularUtils.directives.dirPagination']);

Michael Bromley 在 http://www.michaelbromley.co.uk/blog/108/paginate-almost-anything-in-angularjs#comment-2122947706 中回答

关于javascript - 使用 Angular js 对几乎所有内容进行分页,无法实例化模块错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31273253/

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