angularjs - How to change CSS class after Ajax request in Angular -
i can't figure out i'm supposed use in following situation:
- the template list bunch of photos
- each photo element has ng-click event marks photo selected , sends ajax request save photo
- when save happens, want update class of photo element show selected
i have call tie ng-class works when page loads, called when user clicks. should called after save.
how do this?
thanks lot.
you can write like:
<a ng-click="uploadimage('id')"> <i ng-class="{'image-not-uploaded': !sendimage, 'image-uploaded': sendimage}"></i> </a>
in js
... $scope.sendimage= false; ajax_post.uploadfile_init($scope.uploadedfile) .then(function (result) { if(result.status == 200){ $scope.sendimage= true; } }, function (error) { alert(error.message); });
here, change class according $scope.sendimage
state.
i used factory
upload file can change image.
angular.module('feederliteapp', []).factory('ajax_post', ['$http', function(_http) { return{ uploadfile_init: function(uploadedfile){ var fd = new formdata(); fd.append("uploadedfile", uploadedfile); var upload_promise = _http.post("src/php/data.ajax.php", fd, { headers:{ 'content-type':undefined }, transformrequest:angular.identity }); return upload_promise; } } }]);
Comments
Post a Comment