My goal is to update data using a REST call. I have already made a GET request to populate the form, and upon clicking the update button, I intend to initiate a PUT call. However, instead of successfully executing the PUT call, I encounter a Type Error.
Below is the relevant code snippet:
//service.js
someservice.factory('update', function($resource) {
return $resource(connectionString + 'update', {}, {
put: {
method: "PUT",
isArray:
'Content- false,
headers: {Type': 'application/json',
'cache-control': 'no-cache',
'Pragma': 'no-cache',
'sessionId': gv.sessionId
}
}
})
})
//companyCtrl.js where the update factory is included in controller dependencies
$scope.btnUpdate = function() {
console.log("asd");
update.put({}, {
'data': $scope.data
}, function(data){
if(data.success){
console.log("success");
}
else{
console.log("failure");
}
})
}
In my view, I have a button with ng-click="btnUpdate()"
The console log outputs "asd" indicating that everything is properly connected.
One issue that might be contributing to the problem is that I am utilizing ui-router and including the controller within my state configuration as shown below:
.state('admin.company', {
url: "/company/{_id}",
templateUrl: "./views/partials/company.html",
controller: "companyCtrl"
The error stack trace displays the following message:
TypeError: undefined is not a function
at Scope.$scope.btnUpdate (http://localhost:3000/dist/js/app.min.js:1:6680)
at http://localhost:3000/libs/angular/angular.js:10836:21