<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: thenewave</title>
    <description>The latest articles on DEV Community by thenewave (@thenewave).</description>
    <link>https://dev.to/thenewave</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F330400%2F08bd5f74-f62d-4b63-afeb-7e802daa6791.jpg</url>
      <title>DEV Community: thenewave</title>
      <link>https://dev.to/thenewave</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/thenewave"/>
    <language>en</language>
    <item>
      <title>How can I send a variable from AngularJS to Java?</title>
      <dc:creator>thenewave</dc:creator>
      <pubDate>Wed, 05 Feb 2020 00:18:52 +0000</pubDate>
      <link>https://dev.to/thenewave/how-can-i-send-a-variable-from-angularjs-to-java-1n2a</link>
      <guid>https://dev.to/thenewave/how-can-i-send-a-variable-from-angularjs-to-java-1n2a</guid>
      <description>&lt;p&gt;Hi everyone. Im using the angular tag since its the only one, I dont know if it includes AngularJS as well... 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, based on trying to adapt these two resources:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://docs.angularjs.org/api/ng/service/%24http"&gt;https://docs.angularjs.org/api/ng/service/$http&lt;/a&gt;&lt;br&gt;
&lt;a href="http://hello-angularjs.appspot.com/angularjs-http-service-ajax-post-code-example"&gt;http://hello-angularjs.appspot.com/angularjs-http-service-ajax-post-code-example&lt;/a&gt;&lt;/p&gt;



&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;
javascript
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);
    }
}
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

</description>
      <category>angular</category>
      <category>javascript</category>
    </item>
  </channel>
</rss>
