人!
我正在研究另一个人的一些Angular代码,我正在努力解决问题。我使用bower更新了库(因为我需要一些更新的版本才能完成工作)并且我在主页上收到了来自Angular的错误。错误如下:“错误:[ng:areq]参数'fn'不是函数,未定义”。我试图调试它但没有成功。我在这里也读过很多关于它的内容,但没有任何帮助。从我所看到的问题可能是在app .config()或错误声明的控制器中,或者......谁知道:D
如果您想尝试帮助我,我将提供重要的(在我看来)代码:
1)应用配置:
'use strict';
var agencySeekApp = angular.module('agencySeekApp', ['ngResource', 'ngRoute', 'flang', 'ngCookies', 'agencySeekFilters'])
.value('toastr', toastr)
.config(function($routeProvider, $locationProvider) {
$locationProvider.html5Mode({
enabled: true,
requireBase: false
});
var routeUserChecks = {
adminRole: {
authenticate: function(auth) {
return auth.isAuthorizedForRole('admin');
}
},
authenticated: {
authenticate: function(auth) {
return auth.isAuthenticated();
}
}
};
$routeProvider
.when('/', {
templateUrl: '/app/views/home.html',
controller: 'HomePageCtrl'
})
.when('/category/:categoryId/choose-network/', {
templateUrl: '/app/views/network_pick.html',
controller: 'ChooseNetworkCtrl'
})
.when('/category/:categoryId/network/:networkId', {
templateUrl: '/app/views/schools_pick.html',
controller: 'SchoolPageCtrl'
})
.when('/agencies/:categoryId/:schoolId', {
templateUrl: '/app/views/agency.html',
controller: 'AgencyPageCtrl'
})
.when('/show/agency/:agencyId', {
templateUrl: '/app/views/agency_show.html',
controller: 'ShowAgencyCtrl'
})
.when('/show/school/:schoolId', {
templateUrl: '/app/views/school_show.html',
controller: 'ShowSchoolCtrl'
})
.when('/case/open', {
templateUrl: '/app/views/open_case.html',
controller: 'OpenCaseCtrl'
})
.when('/case/show/:case_id', {
templateUrl: '/app/views/show_case.html',
controller: 'ShowCaseCtrl'
})
.when('/account/retrivePassword', {
templateUrl: '/app/views/account.html',
controller: 'AccountPageCtrl'
})
.when('/search/:search_params',{
templateUrl: '/app/views/search_page.html',
controller: 'SearchPageCtrl'
}).when('/postcode-agencies/category/:categoryId/postcode-id/:postCodeId',{
templateUrl: '/app/views/post_code_agencies.html',
controller: 'PostCodeAgenciesCtrl'
})
/*for delete*/
.when('/sysadmin/network',{
templateUrl: '/app/views/sys_admin_network.html',
controller: 'SysAdminNetworkCtrl'
})
.when('/sysadmin/categories',{
templateUrl: '/app/views/sys_admin_categories.html',
controller: 'SysAdminCategoriesCtrl'
})
.when('/sysadmin/list',{
templateUrl: '/app/views/sys_admin_list.html',
controller: 'SysAdminListCtrl'
})
.when('/sysadmin/users',{
templateUrl: '/app/views/sys_admin_users.html',
controller: 'SysAdminUsersCtrl'
})
/*end*/
/*account*/
.when('/account/cases',{
templateUrl: '/app/views/account_cases.html',
controller: 'AccountCasesCtrl'
})
.when('/account/teachers',{
templateUrl: '/app/views/account_teachers.html',
controller: 'AccountTeachersCtrl'
})
.when('/account/schools',{
templateUrl: '/app/views/account_schools.html',
controller: 'AccountSchoolsCtrl'
})
.when('/account/agencies',{
templateUrl: '/app/views/account_agencies.html',
controller: 'AccountAgenciesCtrl'
})
.when('/account/case_workers',{
templateUrl: '/app/views/account_councilors.html',
controller: 'AccountCouncilorsCtrl'
})
.when('/account/linking',{
templateUrl: '/app/views/account_linking.html',
controller: 'AccountLinkingCtrl'
})
.when('/account/handshaking',{
templateUrl: '/app/views/account_handshaking.html',
controller: 'AccountHandshakingCtrl'
})
.when('/account/myprofile',{
templateUrl: '/app/views/my_profile.html',
controller: 'AccountProfileCtrl'
})
.when('/account/report',{
templateUrl: '/app/views/account_report.html',
controller: 'AccountReportCtrl'
})
.when('/account/admin-settings', {
templateUrl: '/app/views/account_admin_settings.html',
controller: 'AccountAdminSettingsCtrl'
})
/*end*/
.otherwise({
templateUrl: '/app/views/home.html',
controller: 'in_Otherwise'
});
});
2)主页控制员:
angular.module('agencySeekApp')
.controller('HomePageCtrl',['$scope','identity','$http','selectedSchoolCookieService',function($scope,identity,$http,selectedSchoolCookieService){
//$scope.test = 'some test';
$scope.identity = identity;
$http.get('/api/v1/agency/categories')
.success(function(res){
console.log("res : ",res);
$scope.arr = res.data;
})
.error();
var url = '';
var schoolIdCookie = selectedSchoolCookieService.getCookie('schoolId');
$scope.urlForTheUser = function (someId) {
if(identity.currentUser && identity.currentUser.isFromSchool() ){
url = '/agencies/'+someId+'/'+identity.currentUser.school_id+'/';
}else {
if(schoolIdCookie) {
url = '/agencies/' + someId + '/' + schoolIdCookie;
}else {
url = '/category/'+someId+'/choose-network/';
}
}
return url;
};
3)我的index.html中的脚本部分,包括所有脚本(包含订单参考):
<script type="text/javascript" src="/lib/jquery/dist/jquery.min.js"></script>
<script type="text/javascript" src="/lib/charts/jquery.flot.js"></script>
<script type="text/javascript" src="/lib/charts/jquery.flot.pie.js"></script>
<script type="text/javascript" src="/lib/charts/jquery.flot.spline.js"></script>
<script type="text/javascript" src="/lib/jRate-master/dist/jRate.min.js"></script>
<script type="text/javascript" src="/lib/angular/angular.js"></script>
<script type="text/javascript" src="/lib/bootstrap/dist/js/bootstrap.min.js"></script>
<script type="text/javascript" src="/lib/toastr/toastr.js"></script>
<script type="text/javascript" src="/lib/angular-resource/angular-resource.min.js"></script>
<script type="text/javascript" src="/lib/angular-route/angular-route.js"></script>
<script type="text/javascript" src="/lib/angular-cookies/angular-cookies.js"></script>
<script type="text/javascript" src="/lib/angular-sanitize/angular-sanitize.min.js"></script>
<script type="text/javascript" src="/app/flangCharts.js"></script>
<script type="text/javascript" src="/app/app.js"></script>
<script type="text/javascript" src="/app/custom.js"></script>
<script type="text/javascript" src="/app/account/auth.js"></script>
<script type="text/javascript" src="/app/account/identity.js"></script>
<script type="text/javascript" src="/app/account/LoginController.js"></script>
<script type="text/javascript" src="/app/account/usersResource.js"></script>
<script type="text/javascript" src="/app/services/selectedAgencies.js"></script>
<script type="text/javascript" src="/app/services/pageService.js"></script>
<script type="text/javascript" src="/app/services/selectedSchoolCookieService.js"></script>
<script type="text/javascript" src="/app/services/lastPageCategorySelected.js"></script>
<script type="text/javascript" src="/app/directives/fileUploadDirective.js"></script>
<script type="text/javascript" src="/app/directives/popUpAgencyDirective.js"></script>
<script type="text/javascript" src="/app/directives/popUpLinkingDirective.js"></script>
<script type="text/javascript" src="/app/directives/reportDirectives.js"></script>
<script type="text/javascript" src="/app/filters.js"></script>
<script type="text/javascript" src="/app/controllers/HomePageCtrl.js"></script>
<script type="text/javascript" src="/app/controllers/ChooseNetworkCtrl.js"></script>
<script type="text/javascript" src="/app/controllers/ShowAgencyCtrl.js"></script>
<script type="text/javascript" src="/app/controllers/SchoolPageCtrl.js"></script>
<script type="text/javascript" src="/app/controllers/AgencyPageCtrl.js"></script>
<script type="text/javascript" src="/app/controllers/ShowAgencyCtrl.js"></script>
<script type="text/javascript" src="/app/controllers/OpenCaseCtrl.js"></script>
<script type="text/javascript" src="/app/controllers/SearchPageCtrl.js"></script>
<script type="text/javascript" src="/app/controllers/ShowCaseCtrl.js"></script>
<script type="text/javascript" src="/app/controllers/ShowSchoolCtrl.js"></script>
<script type="text/javascript" src="/app/controllers/LeftSideBarCtrl.js"></script>
<script type="text/javascript" src="/app/controllers/PostCodeAgenciesCtrl.js"></script>
<script type="text/javascript" src="/app/controllers/AccountAdminSettingsCtrl.js"></script>
<script type="text/javascript" src="/app/account/user_page_ctrl/SysAdminNetworkCtrl.js"></script>
<script type="text/javascript" src="/app/account/user_page_ctrl/SysAdminListCtrl.js"></script>
<script type="text/javascript" src="/app/account/user_page_ctrl/SysAdminUsersCtrl.js"></script>
<script type="text/javascript" src="/app/account/user_page_ctrl/SysAdminCategoriesCtrl.js"></script>
<script type="text/javascript" src="/app/account/user_page_ctrl/AccountCasesCtrl.js"></script>
<script type="text/javascript" src="/app/account/user_page_ctrl/AccountTeachersCtrl.js"></script>
<script type="text/javascript" src="/app/account/user_page_ctrl/AccountSchoolsCtrl.js"></script>
<script type="text/javascript" src="/app/account/user_page_ctrl/AccountAgenciesCtrl.js"></script>
<script type="text/javascript" src="/app/account/user_page_ctrl/AccountCouncilorsCtrl.js"></script>
<script type="text/javascript" src="/app/account/user_page_ctrl/AccountLinkingCtrl.js"></script>
<script type="text/javascript" src="/app/account/user_page_ctrl/AccountMenuCtrl.js"></script>
<script type="text/javascript" src="/app/account/user_page_ctrl/AccountHandshakingCtrl.js"></script>
<script type="text/javascript" src="/app/account/user_page_ctrl/AccountProfileCtrl.js"></script>
<script type="text/javascript" src="/app/account/user_page_ctrl/AccountReportCtrl.js"></script>
希望这就够了!
祝你好运, 小时。
答案 0 :(得分:2)
我发现了问题。当调用$ http时,我应该链接.success()回调和.error()。问题是.error()需要一个函数参数,而我什么也没提供。修正的是:
.error(function(data, status, headers, config){
console.log(data, status, headers, config);
});
就是这样:))
感谢关于断点的提示。我不敢相信我没有这样做,只是跑到StackOverflow哭:D
无论如何,它已经完成了。感谢@bilpor帮助我!
答案 1 :(得分:0)
很难说清楚这一点。您是否尝试过踩代码来尝试缩小它不喜欢的行。您应该可以使用Chrome浏览器工具并设置断点等。我从您的第一段代码中假设
&n;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; >
存在