我有这样的日志文件。
我的app.js
'使用严格的';
/** * @ngdoc overview * @name placementTestApp * @description * # placementTestApp * * Main module of the application. */ angular.module('placementTestApp', [ 'ngAnimate', 'ngAria', 'ngCookies', 'ngMessages', 'ngResource', 'ngRoute', 'ngSanitize', 'ngTouch' ]) .config(function ($routeProvider) { $routeProvider .when('/', { templateUrl: 'views/beck/partials/home.html', controller:"",controllerAs:"mainCtrl" }) // route for the about page .when('/soal', { templateUrl : 'views/beck/partials/soal.html', controller:"",controllerAs:"soalCtrl" }) .when('/addSoal', { templateUrl : 'views/beck/partials/addSoal.html', controller:"",controllerAs:"addSoalCtrl" }) .when('/user', { templateUrl : 'views/beck/partials/user.html', //controller: 'userCtrl' controller:"userCtrl",controllerAs:"userCtrl" }) .when('/addUser', { templateUrl : 'views/beck/partials/addUser.html', controller:"",controllerAs:"addUserCtrl" }) .when('/level', { templateUrl : 'views/beck/partials/level.html', controller:"",controllerAs:"levelCtrl" }) .when('/addLevel', { templateUrl : 'views/beck/partials/addLevel.html', controller:"",controllerAs:"addLevelCtrl" }) .when('/page', { templateUrl : 'views/beck/partials/page.html', controller:"",controllerAs:"pageCtrl" }) .when('/addPage', { templateUrl : 'views/beck/partials/addPage.html', controller:"",controllerAs:"addPageCtrl" }) .when('/cekDb', { templateUrl : 'views/beck/partials/cekDb.html', controller:"",controllerAs:"cekDbCtrl" }) // route for the contact page .when('/profile', { templateUrl : 'views/beck/partials/profile.html', controller:"",controllerAs:"profileCtrl" }) .otherwise({ redirectTo: '/' }); });
userCtrl.js
'use strict';
angular.module('placementTestApp'[]).controller('userCtrl',[$scope,userCtrl]);
function userCtrl ($scope) {
// body...
//get user
$scope.pagedItems = [];
$scope.get_users = function(){
$http.get("../controllers/user.php?action=get_users").success(function(data){
$scope.pagedItems = data;
})
}
//add user
$scope.user_add = function(){
$http.post('user.php?action=add_user',
'user_name' = $scope.user_name,
'user_email' = $scope.user_email,
'user_pass' = $scope.user_pass
).success(function(data){
$scope.get_users();
}).error(function () {
});
}
//delete user
//update user
//edit user
}
答案 0 :(得分:0)
代码格式化已关闭,但错误消息指向此行:
angular.module('placementTestApp'[]).controller('userCtrl',[$scope,userCtrl]);
你需要在'$scope'
周围加上引号,因为它在那时的目的只是指示角度注入你的控制器的内容,并且在那一点上没有对特定$scope
的实际引用:
angular.module('placementTestApp'[]).controller('userCtrl',['$scope', userCtrl]);
答案 1 :(得分:0)
您应该避免[]
文件模块中的userCtrl.js
,因为您已在同一模块的app.js
文件中注入依赖项。也可以在''
中使用['$scope', ..
(单引号),但不要在函数参数
喜欢:
angular.module('placementTestApp').controller('userCtrl',['$scope', function($scope) {
// your codes here
}]);
确保userCtrl.js
加载index.html
或加载所有js文件。
答案 2 :(得分:0)
这项工作对我来说你可以试试这个。
angular.module('myApp',['ngRoute']).controller('userController',userController);
function userController(){
/* your code */
}