2016-09-20 1 views
0

Ich möchte eine Zugabe (Operation a + b = c) mit JavaRest, Methode GET mit 2 Doppelparameter und AngularJS, um die generierte Ressource zu bekommen, aber ich blockierte immer noch.

hier ist der Code:

//CalculatorResource.java 
@Path("calco") 
public class CalculeteResource { 

double result; 

@GET 
@Path("/addition/{a}/{b}") 
@Produces(MediaType.APPLICATION_JSON) 
public Response getAddition(@PathParam("a") double a, @PathParam("b") double b) { 

    Calculete calco = new Calculete(); 
    calco.setA(a); 
    calco.setB(b); 
    result = calco.getA() + calco.getB(); 
    calco.setC(result); 
    return Response.ok(calco).build(); 
} 

// succesfull Test auf dem Server unter Verwendung von http:

http://localhost:8380/dadem-calculator/rest/calco/addition/5/5

und erzeugte Objekt ist, a + b = c (5 + 5 = 10

)
{"a":5.0,"b":5.0,"c":10.0} 

und hier das Problem: die AngularJS-Controller mit GET + 2 Param:

var app = angular.module("CalculatorManagement", []); 

//Controller 
app.controller("CalculatorController", function($scope, $http) { 

    $scope.result; 
    $scope.operation={ 
      a : 0, 
      b : 0, 
      c : 0 
     }; 


    //HTTP GET- get all users collection 
    function _refreshUserData() { 
     $http({ 
      method : 'GET', 
      url : 'http://localhost:8380/dadem-calculator/rest/calco/addition/' + operation.a + '/' + operation.b 
     }).then(function successCallback(response) { 
      $scope.result = response.data; 
     }, function errorCallback(response) { 
      console.log(response.statusText); 
     }); 
    }; 

}); 

html mit ng-Modell:

 <td><input type="number" ng-model="operation.a"></td> 


     <td><input type="number" ng-model="operation.b"></td> 

     <td> {{ result.c }} </td> 

    </tr> 
+1

Es ist ein Tippfehler in Ihrem http get: + Operation ‚/‘, die Sie vermissen ein ‚+ ". Es sollte + operation.a + '/' sein –

+0

erhalten Sie irgendeinen Fehler in der Konsole? – Aravind

+0

Was sehen Sie auf der Registerkarte Netzwerk Ihrer Developer Tools? – NicolasMoise

Antwort

0

Wo u diese Funktion aufgerufen? Sie müssen dieses Objekt übergeben in dieser Funktion oder einfach Schreib $ scope.operation.a/b

+0

Ich versuche, aber es funktioniert nicht – Manu

+0

Funktion _refreshUserData ($ scope.operation.a/b) { \t \t \t $ http ({ \t \t \t \t Methode: 'GET', \t \t \t \t url: ' http: // localhost: 8380/dadem-Rechner/rest/calco/Additions- /‘+ + Operation '/' operation.b \t \t \t}) dann (Funktion successCallback (Antwort) { \t \t \t \t. $ scope.result = Antwort.dat ein; \t \t \t} Funktion errorCallback (response) { \t \t \t \t console.log (response.statusText); \t \t \t}); \t \t}; \t \t \t \t $ scope.operation.a = result.a; \t \t $ scope.operation.b = Ergebnis.b; \t \t $ scope.operation.c = result.c; – Manu

0
var app = angular.module("CalculatorManagement", []); 
app.controller("CalculatorController", function($scope, $http) { 

$scope.result; 
$scope.operation={ 
     a : 0, 
     b : 0, 
     c : 0 
    }; 


//HTTP GET- get all users collection 
function _refreshUserData() { 
    $http({ 
     method : 'GET', 
     url : 'http://localhost:8380/dadem-calculator/rest/calco/addition/' + $scope.operation.a + '/' + $scope.operation.b 
    }).then(function successCallback(response) { 
     $scope.result = response.data; 
    }, function errorCallback(response) { 
     console.log(response.statusText); 
    }); 
}; 
}); 
Verwandte Themen