I'm trying to make a simple invitation system, and i want to update a specific field "accepted" from false to true for every invite, when i click on accept button in a template. i'm a beginner in AngularJs
Restfull Api in the url /site/invitations/ :
HTTP 200 OK
Allow: GET, POST, HEAD, OPTIONS
Vary: Accept
Content-Type: application/json
[
{
"id": 10,
"user_from_name": "achref97",
"accepted": false,
"deleted": false,
"user_from": 22,
"user_to": 24,
}
]
template.html :
<div class="col-lg-7 col-md-6 no-pd" ng-app="isamm.demo" >
<div class="main-ws-sec">
<div class="posts-section">
<div class="post-bar">
<div class="job_descp" ng-controller="InvitationController">
{% verbatim %}
<div ng-repeat="invite in invitations">
<h3>pour {{invite.user_from}}</h3>
<button ng-click="update()">accept</button>
</div>
{% endverbatim %}
</div>
</div>
</div>
</div>
</div>
JavaScript : As you can see i retrieve the list of invitations from /site/invitations/, then in the template i create a button with update() function, but i can't continue from there, any help?.
(function(){
'use strict';
var app = angular.module('isamm.demo', []);
app.controller('InvitationController', function ($scope,$http) {
$scope.invitations= [];
$http.get('/site/invitations/').then(function(response){
$scope.invitations= response.data;
});
$scope.update = function (){
// What to do here?
};
});
}());
$scope.update = function (id){
$scope.invitations.filter(invite => {
if (id === invite.id) {
invite.accepted = true;
}
});
};
and pass invite.id to update method in markup
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.