Kemal P. Kemal P. - 4 months ago 8
AngularJS Question

TypeError: Complaint.get is not a function

Im getting this error:

TypeError: ComplaintData.get is not a function


Could somebody tell me please why it's showing that error? What could cause this error? The service is injected into the controller but i dont know what could be causing the error.

Controller:

(() => {

angular
.module('app')
.controller('complaintController', complaintController)

complaintController.$inject = ['$http', '$rootScope', 'Complaint']

function complaintController($rootScope, Complaint) {

var vm = this;
vm.array = [];

Complaint.get()
.success((info) => {
vm.array = data
})
.error(() => {
$scope.error = data
})
.................


Service:

(() => {
angular
.module('app')
.service('Complaint', complaintInfoService)

function complaintInfoService($http) {

function getInfo() {
return http.get('/user/info/')
}

function createComplaint(data) {
return $http.post('/user/complaints', {data: data})
}

return {
get: getInfo,
create: createComplaint
}
}

})();

Answer

on your controller you forgot to declare the $http variable

function complaintController($http, $rootScope, Complaint) //add $http in front

now you are trying to access the get method from $rootscope

Comments