While working on my CRUD angularApp, I encountered a strange error in Chrome dev tools. Here is the complete error message:
error: [ng:areq] http://errors.angularjs.org/1.3.2/ng/areq?p0=DbController&p1=not%20a%20function%2C%20got%20string
at angular.js:38
at Nb (angular.js:1577)
at ob (angular.js:1587)
I have checked DbController thoroughly but couldn't find any issues. All references to DbController are provided below.
Index.php
<html ng-app="crudApp">
... <!-- stylesheet and scripts added -->
<body>
<div class="container wrapper" ng-controller="DbController">
...
script.js
// Application module
var crudApp = angular.module('crudApp', []);
crudApp.controller("DbController", ['$scope', '$http', function($scope, $http) {
// Function to fetch employee details from the database
getInfo();
function getInfo() {
// Sending request to EmpDetails.php files
$http.post('databaseFiles/empDetails.php').success(function(data) {
// Storing the returned data into scope
$scope.details = data;
});
}
$scope.insertInfo = function(info) {
$http.post('databaseFiles/insertDetails.php', {
"name": info.name,
"email": info.email,
"address": info.address,
"gender": info.gender
}).success(function(data) {
if (data == true) {
getInfo();
// Hide details insertion form
$('#empForm').css('display', 'none');
}
});
};
$scope.currentUser = {};
$scope.editInfo = function(info) {
$scope.currentUser = info;
$('#empForm').slideUp();
$('#editForm').slideToggle();
};
$scope.UpdateInfo = function(info) {
$http.post('databaseFiles/updateDetails.php', {
"id": info.emp_id,
"name": info.emp_name,
"email": info.emp_email,
"address": info.emp_address,
"gender": info.emp_gender
}).success(function(data) {
$scope.show_form = true;
if (data == true) {
getInfo();
}
});
};
$scope.deleteInfo = function(info) {
$http.post('databaseFiles/deleteDetails.php', {
"del_id": info.emp_id
}).success(function(data) {
if (data == true) {
getInfo();
}
});
};
}]);
If you notice any issue with the DBController code, please do let me know.