From aa1e50f4124f5861a2ea9a4014c897bf29a59d1b Mon Sep 17 00:00:00 2001 From: Johannes Geppert Date: Wed, 6 May 2015 20:34:35 +0200 Subject: [PATCH 1/2] Remove unused dependency from ApacheProjectsController --- .../archetype-resources/src/main/webapp/js/controllers.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/archetypes/struts2-archetype-angularjs/src/main/resources/archetype-resources/src/main/webapp/js/controllers.js b/archetypes/struts2-archetype-angularjs/src/main/resources/archetype-resources/src/main/webapp/js/controllers.js index ed57b00e9..f0d72f1e3 100644 --- a/archetypes/struts2-archetype-angularjs/src/main/resources/archetype-resources/src/main/webapp/js/controllers.js +++ b/archetypes/struts2-archetype-angularjs/src/main/resources/archetype-resources/src/main/webapp/js/controllers.js @@ -24,7 +24,7 @@ angularStrutsApp.controller('HomeController', function ($scope) { $scope.name = "Sunshine"; }); -angularStrutsApp.controller('ApacheProjectsController', function ($scope, $http, DataService) { +angularStrutsApp.controller('ApacheProjectsController', function ($scope, DataService) { this.init = function() { DataService.getProjects().then(function(data) { $scope.projects = data.data.projectNames; From 01279636d9160508dc94151e19e47a74ddf319aa Mon Sep 17 00:00:00 2001 From: Johannes Geppert Date: Wed, 6 May 2015 20:49:29 +0200 Subject: [PATCH 2/2] Correct usage of promises and improve logging in data service --- .../src/main/webapp/js/controllers.js | 8 ++++---- .../src/main/webapp/js/services.js | 15 ++++++++------- 2 files changed, 12 insertions(+), 11 deletions(-) diff --git a/archetypes/struts2-archetype-angularjs/src/main/resources/archetype-resources/src/main/webapp/js/controllers.js b/archetypes/struts2-archetype-angularjs/src/main/resources/archetype-resources/src/main/webapp/js/controllers.js index f0d72f1e3..07f12d773 100644 --- a/archetypes/struts2-archetype-angularjs/src/main/resources/archetype-resources/src/main/webapp/js/controllers.js +++ b/archetypes/struts2-archetype-angularjs/src/main/resources/archetype-resources/src/main/webapp/js/controllers.js @@ -24,12 +24,12 @@ angularStrutsApp.controller('HomeController', function ($scope) { $scope.name = "Sunshine"; }); -angularStrutsApp.controller('ApacheProjectsController', function ($scope, DataService) { +angularStrutsApp.controller('ApacheProjectsController', function ($scope, $log, DataService) { this.init = function() { DataService.getProjects().then(function(data) { - $scope.projects = data.data.projectNames; - }, function(data) { - console.log('Could not receive project names.') + $scope.projects = data.projectNames; + }, function() { + $log.error('Could not receive project names.') }); }; diff --git a/archetypes/struts2-archetype-angularjs/src/main/resources/archetype-resources/src/main/webapp/js/services.js b/archetypes/struts2-archetype-angularjs/src/main/resources/archetype-resources/src/main/webapp/js/services.js index e3be1de3e..10ec86749 100644 --- a/archetypes/struts2-archetype-angularjs/src/main/resources/archetype-resources/src/main/webapp/js/services.js +++ b/archetypes/struts2-archetype-angularjs/src/main/resources/archetype-resources/src/main/webapp/js/services.js @@ -18,7 +18,7 @@ * specific language governing permissions and limitations * under the License. */ -angularStrutsApp.factory('DataService', ['$http', '$q', function($http, $q) { +angularStrutsApp.factory('DataService', ['$http', '$log', '$q', function($http, $log, $q) { var DataService = { urls : { @@ -32,18 +32,19 @@ angularStrutsApp.factory('DataService', ['$http', '$q', function($http, $q) { } var def = $q.defer(); if(method === 'GET') { - return $http.get(url).success(function(data) { - DataService.data = data; + $http.get(url).success(function(data) { def.resolve(data); - }).error(function() { - def.reject("Failed to get data"); + }).error(function(data, code) { + def.reject(data); + $log.error(data, code); }); } else if(method === 'POST'){ $http.post(url, model).success(function(data) { DataService.data = data; def.resolve(data); - }).error(function() { - def.reject("Failed to post data"); + }).error(function(data, code) { + def.reject(data); + $log.error(data, code); }); } return def.promise;