Rick GZ Rick GZ - 6 months ago 80
AngularJS Question

Using $http in angular jhipster entities

What is the proper way to update some entity field from Angular view/controller.

Let's imagine we have a"to-do" app in which we want to change "Task" entity status from 1 to 0 from a ng-click event and store that change in the database.

How can we create that functionality in our controller so we can call it when checking/unchecking a checkbox?

Lets set the playground:

<div ng-repeat="task in tasklist.tasks">

<checkbox ng-change="completeTask({{taskId:task.id}})"></checkbox>


In Controller we want to change "task.status" from 1 to 0 or viceversa when checkbox click:

//If we need to obtain that task object from api
var task = Task.get({id : $stateParams.taskId}).$promise;

//Now how should the function work?

$scope.completeTask = function () {



JHipster exposes a REST API so to update an existing task either you use PUT /api/tasks/123 with the full entity or you define a sub resource and you use POST /api/tasks/123/complete and return a 303 HTTP status code.

Do some research about PUT/POST and partial updates in REST.

Then in angular part, with first approach, generated task.service.js has everything you need with update function, second approach requires more work.