Advertisement
Guest User

Untitled

a guest
Jun 12th, 2018
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.44 KB | None | 0 0
  1. 'use strict';
  2.  
  3. angular.module('myApp.view3', ['ngRoute'])
  4.  
  5. .config(['$routeProvider', function ($routeProvider) {
  6. $routeProvider.when('/view3', {
  7. templateUrl: 'view3/view3.html',
  8. controller: 'View3Ctrl'
  9. });
  10. }])
  11.  
  12. .controller('View3Ctrl', ['$scope', '$http', function ($scope, $http) {
  13.  
  14. $scope.myData = new Array();
  15.  
  16. $scope.getDataFromServer = function () {
  17. $http({
  18. method: 'GET',
  19. url: 'http://localhost:8080/users'
  20. }).then(function successCallback(response) {
  21. $scope.myData = response.data;
  22. console.log(response.data);
  23. }, function errorCallback(response) {
  24. console.log(response);
  25. });
  26. };
  27.  
  28. $scope.pushDataToServer = function () {
  29.  
  30. var newObject;// = new Array();
  31. newObject.username=Username;
  32. newObject.firstname=firstname;
  33. newObject.lastname=lastname;
  34. newObject.email=email;
  35. newObject.password=password;
  36. newObject.phone=phone;
  37.  
  38. var json = angular.toJson(newObject);
  39.  
  40. $http({
  41. method: 'POST',
  42. url: 'http://localhost:8080/users',
  43. headers: {
  44. 'Content-Type': 'application/json',
  45. 'Accept': 'application/json'
  46. },
  47. data: json
  48. }).then(function successCallback(response) {
  49. console.log(response);
  50. $scope.getDataFromServer();
  51. }, function errorCallback(response) {
  52. console.log(response);
  53. });
  54.  
  55. };
  56.  
  57. }]);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement