i'm new angularjs. have simple java restful service return json. , function in collector:
angular.module('testapp').controller('logincontroller', function($scope, $http, $timeout, $resource) { $scope.mapp_login_email = ''; $scope.mapp_login_password=''; $scope.loginapi = function() { var baseurl = 'http://localhost:8080'; $scope.loginapi = $resource(baseurl + '/api/login/post', {}, { login2: {method: 'post'} }); var response = $scope.loginapi.login2({ email: $scope.mapp_login_email, password: $scope.mapp_login_password }); response.$promise.then(function(value) { var data = json.stringify(value, ['returncode', 'errmsg']); $scope.mapp_login_email = data.returncode; }); }
});
the restful service being called , see in network tab returns json response:
{returncode: "ok", status: 0, errmsg: null}
how can evaluated in angularjs code return value restful service?
thanks, ronen
there cleaner way use http angular. try $http service.
var baseurl = 'http://localhost:8080'; $http .post(baseurl + '/api/login/post', null, { email: $scope.mapp_login_email, password: $scope.mapp_login_password }) .then(function successcallback(response) { // on success console.log(response); }, function errorcallback(response) { // on error console.log(response); });
Comments
Post a Comment