angularjs - Where does the error event go in Angular when using a factory? -


i have code below working need create handler when error occurs not sure how insert that.. put in factory on in main method?

msaapp.factory('msa', function ($resource) { return $resource('/api/place/:id', { id: '@id' }, { update: { method: 'put' } }); 

});

 $scope.delete = function () {     debugger;     var id = this.msa.placeid;     msa.delete({ id: id }, function () {         $('#todo_' + id).fadeout();     }); } 

edit 1:

 $scope.delete = function () {     debugger;      // var id = this.msa.placeid;      var config = {         method: 'put',         url: 'api/place/:id',         data: { 'some': 'data' }     }      $http(config)     .success(function (data, status, headers, config) {         console.log(data);     })     .error(function (data, status, headers, config) {         console.log(data);     });       //msa.delete({ id: id }, function () {     //    $('#todo_' + id).fadeout();     //}); } 

first of sugest moving dom manipulation directive , let controller supposed do.

and answer question ( hope understood correctly ):

msaapp.factory('msa',['$http', function(http) {     return {          delete: function(somedata) {              var config = {                 method: 'put',                 url: '/api/place/:id',                 data : somedata             };              http(config)             .success(function(data, status, headers, config) {                  console.log(data);              })             .error(function(data, status, headers, config) {                     console.log(data);             });            }}      }; }])  msaapp.controller('controllername', ['$scope', 'msa', function(scope, msa) {      $scope.delete = function({ id: id }) {          debugger;          msa.delete({ id: id });          $('#todo_' + id).fadeout();      };  }]) 

if factory cant access controller scope , wish return, example messages controller need use promise explained here: http://markdalgleish.com/2013/06/using-promises-in-angularjs-views/


Comments

Popular posts from this blog

java - Run a .jar on Heroku -

java - Jtable duplicate Rows -

validation - How to pass paramaters like unix into windows batch file -