Hi everyone. I've been trying to send a variable inside of a JS Controller to my Java server using $http, but I cant get it to work: once I try it out, I cant enter the HTML view in which this JS code is used, so the problem is coming from the JS controller. Here's what I am doing and the code (in which I left some doubts), based on trying to adapt these two resources:
https://docs.angularjs.org/api/ng/service/%24http http://hello-angularjs.appspot.com/angularjs-http-service-ajax-post-code-example angular .module('myApp') .controller('MessageController', MessageController); MessageController.$inject = ['$scope', '$stateParams', '$uibModalInstance', 'MessageTemplate', 'JhiLanguageService']; onFormatChange.$inject = ['$resource', '$http', 'ServerURL']; // should it be vm.onFormatChange.$inject instead? function MessageController ($scope, $stateParams, $uibModalInstance, MessageTemplate, JhiLanguageService) { var vm = this; vm.isSaving = false; vm.text = 'Activated'; // this is the only variable // im trying to send to Java function onSaveSuccess (result) { // a console.log } function onSaveError (error) { // a console.log } // this function gets called from the HTML via ng-change vm.onFormatChange = function () { vm.text = vm.status ? 'Deactivated' : 'Activated'; // Sending vm.text (as "format") to the server $http.post(ServerURL + 'api/format/', { format: vm.text // should it be format = vm.text? }. {withCredentials: true, headers: { 'Content-Type': 'application/json; charset=utf-8', 'Access-Control-Allow-Origin': true, 'X-Requested-With': 'XMLHttpRequest' } }).then(onSaveSuccess, onSaveError); } } -- You received this message because you are subscribed to the Google Groups "Angular and AngularJS discussion" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To view this discussion on the web visit https://groups.google.com/d/msgid/angular/af646c15-d1ef-4277-8359-877f2ea93a0f%40googlegroups.com.
